AFNetworking - 偶尔在 http 响应上得到 "unacceptable content type: application/json"
AFNetworking - occasionally get "unacceptable content type: application/json" on http response
我不明白为什么 AFNetworking 2.0 会抛出此消息。我的理解是 application/json 是默认的序列化方案,所以如果服务器 returns JSON 的内容类型为:application/json,为什么 AFNetworking 会抛出这个错误?
Failure with messages Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/json" UserInfo=0x17e2ed60 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x17e84100> { URL: http://XXX/XXX/XXX } { status code: 200, headers {
Connection = "keep-alive";
"Content-Type" = "application/json;charset=UTF-8";
Date = "Fri, 14 Aug 2015 16:16:52 GMT";
Server = "Apache-Coyote/1.1";
"Transfer-Encoding" = Identity;
"X-Application-Context" = application;
} }, NSErrorFailingURLKey=http://XXX/XXX/XXX, NSLocalizedDescription=Request failed: unacceptable content-type: application/json, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a3230 302c2263 6f646522 3a225636 594d227d>}
在代码块中用 X 注释掉了 URL。这只是有时发生,它会导致请求失败。如果我发出另一个请求,它会成功。
我正在使用 AFHTTPSessionManager 单例来发出所有请求。
试试这个:
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
我不明白为什么 AFNetworking 2.0 会抛出此消息。我的理解是 application/json 是默认的序列化方案,所以如果服务器 returns JSON 的内容类型为:application/json,为什么 AFNetworking 会抛出这个错误?
Failure with messages Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/json" UserInfo=0x17e2ed60 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x17e84100> { URL: http://XXX/XXX/XXX } { status code: 200, headers {
Connection = "keep-alive";
"Content-Type" = "application/json;charset=UTF-8";
Date = "Fri, 14 Aug 2015 16:16:52 GMT";
Server = "Apache-Coyote/1.1";
"Transfer-Encoding" = Identity;
"X-Application-Context" = application;
} }, NSErrorFailingURLKey=http://XXX/XXX/XXX, NSLocalizedDescription=Request failed: unacceptable content-type: application/json, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a3230 302c2263 6f646522 3a225636 594d227d>}
在代码块中用 X 注释掉了 URL。这只是有时发生,它会导致请求失败。如果我发出另一个请求,它会成功。
我正在使用 AFHTTPSessionManager 单例来发出所有请求。
试试这个:
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];