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、解決:在網(wǎng)上查了好多資料,有人說是加如下代碼:可還是不對
//---------
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);