gpt4 book ai didi

objective-c - AFNetworking - 偶尔会在 http 响应上得到 "unacceptable content type: application/json"

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:02 25 4
gpt4 key购买 nike

我不明白为什么 AFNetworking 2.0 会抛出此消息。我的理解是 application/json 是默认的序列化方案,所以如果服务器返回 content-type:application/json 的 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];

关于objective-c - AFNetworking - 偶尔会在 http 响应上得到 "unacceptable content type: application/json",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32014588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com