8、使用AFNetwroking请求错误 输出Bug
2016-04-12 本文已影响1905人
天听云道
1、错误:请求错误时,error错误信息如下,这样我们找不出错误原因,无法展示给用户。
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: client error (422)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f9210fb3d20> { URL: http://xxxxxxx.com/orders/cash_search.json } { status code: 422, headers {
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 12 Apr 2016 05:43:01 GMT";
Server = "nginx/1.6.2";
"Transfer-Encoding" = Identity;
Vary = Origin;
"X-Frame-Options" = ALLOWALL;
"X-Request-Id" = "as6778e2-fdc7-43ee-a29e-24d264a513a1";
"X-Runtime" = "0.050252";
} }, NSErrorFailingURLKey=http://xxxxxxxx.com/orders/cash_search.json, com.alamofire.serialization.response.error.data=<7b226d65 73736167 65223a22 e69caae6 89bee588 b0e8aea2 e58d9521 227d>, NSLocalizedDescription=Request failed: client error (422)}
2、解决:在网上查了好多资料,有人说是加如下代码:可还是不对
//---------
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html", nil];
//---------
最后加了如下这样代码的,输入才正常:
NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
NSLog(@"error--%@",serializedData);