Post请求,向服务器发送用户信息
#define kRegist @"http://api.sucar.com.cn/mobile/index.php?app=mobile&controller=member&action=register"
#define kland @"http://api.sucar.com.cn/mobile/index.php?app=mobile&controller=member&action=login"
@property(nonatomic,strong)UITextField *userName;
@property(nonatomic,strong)UITextField *passWord;
@property(nonatomic,strong)UITextField *email;
-(void)regist
{
? ? NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:kRegist]];
//設(shè)置請(qǐng)求類型
? ? [request setHTTPMethod:@"post"];
? ? NSString * body=[NSString stringWithFormat:@"username=%@&password=%@&email=%@",self.userName.text,self.passWord.text,self.email.text];
? ? NSData *data=[body dataUsingEncoding:NSUTF8StringEncoding];
//設(shè)置包體
? ? [request setHTTPBody:data];
? ? [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
? ? ? ? NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
? ? ? ? NSString *result=dict[@"message"];
? ? ? ? NSString *s=dict[@"state"];
? ? ? ? NSInteger state=[s integerValue];
? ? ? ? if (state==0) {
?? ? ? ? ? UIAlertView *wrong=[[UIAlertView alloc] initWithTitle:@"警告" message:result delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
? ? ? ? ? ? [wrong show];
? ? ? ? }else if(state==1)
? ? ? ? {
? ? ? ? ? ? UIAlertView *right =[[UIAlertView alloc] initWithTitle:nil message:@"注冊(cè)成功" delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
? ? ? ? ? ? [right show];
? ? ? ? }
? ? }];
}
轉(zhuǎn)載于:https://www.cnblogs.com/xiangli/p/4207054.html
總結(jié)
以上是生活随笔為你收集整理的Post请求,向服务器发送用户信息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 受尽侮辱的语言
- 下一篇: C#调用百度地图 api