【发布时间】:2017-01-31 05:21:13
【问题描述】:
我在我的项目中使用 AFNetworking 框架并通过 AFHTTPSessionManager 类访问 web 服务,如下方式,
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 .....
谁能告诉我我做错了什么以及如何解决这个问题?
【问题讨论】:
-
报错,最好先检查一下邮递员是否给出完整的响应?
-
您在响应中得到了哪种响应。添加该代码的某种格式。
-
你好@KKRocks 我已经在上面添加了
Printing description of error: -
是这个格式吗:12112,23131,31231331,312231 .....
标签: php ios objective-c laravel afnetworking