在之前版本 AFHTTPRequestOperation *operation 错误返回可以获取body
operation.responseObject 就是你想要的body内容
但是升级3.0后米有了,后台大哥把错误信息放在body中怎么都获取不到.
最终是在3.0后的error信息中有打印
{ URL: http://api } { status code: 400, headers {
Allow = "POST, OPTIONS";
Connection = "keep-alive";
"Content-Type" = "application/json; charset=utf-8";
Date = "Tue, 05 Jul 2016 03:09:46 GMT";
Server = "nginx/1.6.2";
"Transfer-Encoding" = Identity;
Vary = "Accept, Cookie";
} }, NSErrorFailingURLKey=http://integrate.aidangjia.h2ome.cn/api/v1/users, com.alamofire.serialization.response.error.data=<7b226572 726f7273 223a207b 22646574 61696c22 3a20225c 75396138 635c7538 6263315c 75373830 315c7539 3531395c 75386265 66227d7d>, NSLocalizedDescription=Request failed: bad request (400)}
没错就是这个data=<7b226572 726f7273 223a207b 22646574 61696c22 3a20225c 75396138 635c7538 6263315c 75373830 315c7539 3531395c 75386265 66227d7d>
NSData *data = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
id body = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@", body); 就可以获取到错误时返回的body信息。
网友评论