gpt4 book ai didi

ios - 请求失败 : unacceptable content-type: text/plain using AFNetworking 2. 0

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:16:08 25 4
gpt4 key购买 nike

我在使用 AFNetworiking 2 进行请求时遇到了问题。

我在我的 sharedInstance 类方法中有我的 AFHTTPSessionManager 自定义 sharedInstance

sharedInstance.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:3];
sharedInstance.responseSerializer.acceptableContentTypes = [sharedInstance.responseSerializer.acceptableContentTypes setByAddingObject:@"text/plain"];
sharedInstance.responseSerializer.acceptableContentTypes = [sharedInstance.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];

这是因为我的服务器以 text/plain 响应(仅在错误时 - 成功时它以 json 响应)

但即便如此,当我发送 POST 方法时,我也会收到此错误:

failure: error: Error Domain=NSCocoaErrorDomain Code=3840 
"The operation couldn’t be completed. (Cocoa error 3840.)"
(JSON text did not start with array or object and option to allow fragments not set.)
UserInfo=0x175e6970 {NSDebugDescription=JSON text did not start with array or object
and option to allow fragments not set., NSUnderlyingError=0x175e59b0 "Request failed:
internal server error (500)"}

我读过问题:thisthis以及网络上的更多内容,但没有好的答案。有什么想法吗?

最佳答案

尝试这样的事情:

AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:url]];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];

关于ios - 请求失败 : unacceptable content-type: text/plain using AFNetworking 2. 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23350585/

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