我在我的项目中使用AFNetworking框架&通过AFHTTPSessionManager类访问webservice,如下所示,
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setTimeoutInterval:30];
NSDictionary *parametersDictionary = @{
@"users_id":userIDStr,
@"name" :@""
};
[manager POST:@"api/call_XAPI?"
parameters:parametersDictionary
progress:^(NSProgress * _Nonnull uploadProgress) {
}
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"Success");
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@", error);
}];
这在成功时正常工作,但是如果在服务器中发生任何错误,则错误响应无法在控制台上获得正确的格式
Printing description of error:
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x608000435940> { URL: http://www.example.com/api/call_XYZAPI? } { status code: 500, headers {
"Cache-Control" = "no-cache";
Connection = "keep-alive";
"Content-Type" = "application/json";
Date = "Mon, 30 Jan 2017 13:12:59 GMT";
Server = "nginx/1.10.2";
"Set-Cookie" = "laravel_session=ca9b0725b981267be1f095bb6ae14a1d5ae2825f; expires=Mon, 30-Jan-2017 15:12:59 GMT; Max-Age=7200; path=/; httponly";
"Transfer-Encoding" = Identity;
} }, NSErrorFailingURLKey=http://www.example.com/api/call_XYZAPI?, com.alamofire.serialization.response.error.data = 12112,23131,31231331,312231 .....
谁能告诉我我做错了什么?如何解决这个问题?