ios - AFNetworking 错误信息:NSCocoaErrorDomain Code=3840
天蓬老师
天蓬老师 2017-04-17 17:31:26
0
4
914

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=<NSHTTPURLResponse: 0x15d4c7d0> { 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 的配置问题。

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(4)
Peter_Zhu

The data returned by the server is not in json format. Just let the backend adjust it. This is the most common mistake.

大家讲道理

When this happens, the most common reason is that the interface adds printing information, or the interface throws an error, causing the data returned by the request to be not legal JSON and an error is reported

迷茫

Correct answer on the first floor, this problem has been encountered before, that is, the data returned by the interface is not in standard json format, which may be caused by line breaks or other symbols.

刘奇

@Aster0id, @biaoge, @Na爱利懇 are indeed caused by the server. Thanks.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template