gpt4 book ai didi

ios - AFNetworking 正在从网络服务获取信息,但出现错误。错误域=AFNetworkingErrorDomain 代码=-1016

转载 作者:行者123 更新时间:2023-11-29 03:27:08 24 4
gpt4 key购买 nike

这是我用于从 web 服务获取 json 的代码

NSURL *url = [NSURL URLWithString:BaseURLString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Dictionary %@",(NSDictionary*)JSON);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}];

[operation start];

我得到了正确的信息,但在这样的失败 block 中

Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html" UserInfo=0xaa58030 {NSLocalizedRecoverySuggestion=" MYDATA in form of dictionary "

任何人都可以指导我我的代码有什么问题

编辑:

我添加了这个但是没有效果

[AFJSONRequestOperation addAcceptableContentTypes:
[NSSet setWithObject:@"text/plain"]];

最佳答案

您的代码没有任何问题,您的服务器端有问题,它向您发送 text/html 类型的响应,而不是 text/json 或类似的响应。检查您的服务器端,例如,如果您尝试访问需要授权的资源,您可能会收到 html 错误页面而不是 json 数据。

关于ios - AFNetworking 正在从网络服务获取信息,但出现错误。错误域=AFNetworkingErrorDomain 代码=-1016,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20312452/

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