清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
/登录过程 - (IBAction)logIn:(id)sender { //1.确定地址url NSString *urlString =@"http://www.xxx.com/Api/user.php"; NSURL *url =[NSURL URLWithString:urlString]; //2.建立请求 // 1.建立请求,是要修改请求,所以要用NSMutableURLReque NSMutableURLRequest *requestion =[NSMutableURLRequest requestWithURL:url]; // 2.建立请求超时时间 [requestion setTimeoutInterval:4.0]; // 3.指定请求方法为POST方法,大小不分 [requestion setHTTPMethod:@"post"]; // 4.建立请求数据体,因为要发这个数据题传送给服务器 NSLog(@"iphone=[%@]",logIphone.text); NSLog(@"itext=[%@]",logNum.text); NSString *strinhBody =[NSString stringWithFormat:@"auth=iorgane_cup&mobile=%@&password=%@&action=check_user_login&sign=yyyyyy",logIphone.text,logNum.text]; //将生产的字符串转换成数据 NSData *body =[strinhBody dataUsingEncoding:NSUTF8StringEncoding]; //5把数据体设置给请求 [requestion setHTTPBody:body]; //登录:利用post(数据体:包含电话号码和验证码),上传服务器,然后服务器回复状态 NSURLResponse *response =nil; NSError *error=nil; NSData *data =[NSURLConnection sendSynchronousRequest:requestion returningResponse:&response error:&error]; NSLog(@"访问完成"); if(error !=nil) { NSLog(@"访问出错:%@",error.localizedDescription); return; } if (data !=nil) { NSString *string =[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"string=[%@]",string); NSMutableDictionary *array =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; NSString *pathFile =[[NSBundle mainBundle]pathForResource:@"orange.plist" ofType:nil]; [array writeToFile:pathFile atomically:YES]; NSLog(@"%@",[array objectForKey:@"result"]); if (_logList ==nil) { _logList =[[NSMutableString alloc]init]; } _logList =[array objectForKey:@"result"]; NSLog(@"_logList=[%@]",_logList); if ([_logList isEqualToString:@"true"]) { NSLog(@"登录成功"); } else { NSLog(@"登录失败,请查看密码与用户名是否正确"); return; } } else { NSLog(@"没有收到任何数据"); } }