ios - AFNetworking 错误信息:NSCocoaErrorDomain Code=3840

 青锋寒万岁 发布于 2022-10-29 14:33

App 使用很久了,昨天出现一个bug,网络请求总失败。调试打印,发现是这样的错误:

AFHTTPRequestOperation *operation = [manager POST:URLString parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
    if (successBlock) {
        successBlock(responseObject);
    }
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    if (failureBlock) {
        failureBlock(error);
    }
    NSLog(@"%@", error);
}];

Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set., NSUnderlyingError=0x15eb52e0 {Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad gateway (502)" UserInfo={com.alamofire.serialization.response.error.response= { URL: http://xxx.com } { status code: 502, headers { Connection = "keep-alive"; "Content-Length" = 173; "Content-Type" = "text/html"; Date = "Mon, 01 Feb 2016 03:35:51 GMT"; Server = "nginx/1.5.12"; } }, NSErrorFailingURLKey=http://xxx.com, NSLocalizedDescription=Request failed: bad gateway (502)

有大神遇到过吗?App 使用很久了,头一次出现这样的 bug, 因此可以排除 manager 的配置问题。

4 个回答
  • @Aster0id , @标哥 , @那爱离殇 ,确实是服务器的原因。谢了。

    2022-10-30 15:53 回答
  • 一楼正解,这个问题以前老是遇到过,就是接口返回的数据非标准json格式,有可能是换行符或者其他符号导致的。

    2022-10-30 15:53 回答
  • 出现这种情况,最常见的是接口添加了打印信息,或者接口抱错,导致请求所返回来的数据不是合法的JSON而报错

    2022-10-30 15:54 回答
  • 服务器返回数据不是json格式的,让后端调一下就成,这是最常见的错误了。

    2022-10-30 15:56 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有