gpt4 book ai didi

ios - 带有文本/纯文本响应的 API 失败,返回 'unacceptable content-type'

转载 作者:行者123 更新时间:2023-11-28 21:22:51 26 4
gpt4 key购买 nike

我正在尝试执行一个 GET 请求,该请求以“text/plain”响应

请求失败,错误为“ Not Acceptable 内容类型:文本/纯文本”。

所以我将 AcceptableContentType 设置为 "text/plain" 并使用 NSJSONReadingAllowFragments 创建了一个 responseSerializer



但请求也因错误而失败。




NSCocoaErrorDomain" - code: 3840" : "Invalid value around character 0."




      NSString *requestUrl = [NSString
stringWithFormat:@"%@%@",kServerURL,myURL];

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer
serializerWithReadingOptions:NSJSONReadingAllowFragments];

[manager.responseSerializer
setAcceptableContentTypes:[NSSet setWithObject:@"text/plain"]];
[manager GET:requestUrl
parameters:nil
progress:nil
success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: %@", responseObject);
}
failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];

最佳答案

在这个地方

manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer
serializerWithReadingOptions:NSJSONReadingAllowFragments];
[manager.responseSerializer
setAcceptableContentTypes:[NSSet setWithObject:@"text/plain"]];

使用

    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];

关于ios - 带有文本/纯文本响应的 API 失败,返回 'unacceptable content-type',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39248558/

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