各种坑,有木有。。。
2014-04-17 本文已影响609人
Ghstart
1.AFNetwork
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *reqStr = [NSString stringWithFormat:@"%@%@.do",@"http://172.20.0.11:8080/quickLogin/quickApp/tom/",_contentStr];
[manager GET:reqStr
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
float sta = [[responseObject objectForKey:@"status"] floatValue];
if (sta == 1) {
[self alShow:@"PC端成功登录"];
}else if (sta == 0){
[self alShow:@"PC端登录失败"];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error:%@",error);
}];
其实这个没什么问题,主要就是,你要让服务器端考虑周全,要不然你这里将会遇到一堆蛋疼的Bug。
{ status code: 200, headers {
"Content-Length" = 12;
"Content-Type" = "text/plain;charset=ISO-8859-1";
Date = "Thu, 17 Apr 2014 09:38:46 GMT";
Server = "Apache-Coyote/1.1";
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}
这里一看就知道是服务器端格式问题,服务器端没有设置好,只是设置成了text/plain,假如非要你那里改也是可以的,加上这个:
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
但是你这样改了之后,成功后返回的responseObject解析要出问题了,所以还是服务器端统一做一下处理把!
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x17d72560'
还有一些bug基本上,你直接copy错误,stackoverflow上就能找到答案了,我就不废话了。