目前app项目已经稳定运行2年。但是最近突然出现部分用户接口请求失败的情况。
接口程序日志里看不到错误。
具体返回报错如下
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=0x280768090 {Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={NSLocalizedDescription=Request failed: internal server error (500), NSErrorFailingURLKey=https://110.37.6.140:8100/AppInterface/app/appSendSMS, com.alamofire.serialization.response.error.data={length = 186, bytes = 0x3c68746d 6c3e0d0a 3c686561 643e3c74 ... 2f68746d 6c3e0d0a }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x2808d4d40> { URL: https://110.37.6.140:8100/AppInterface/app/appSendSMS } { Status Code: 500, Headers {
Connection : [
close
],
Content-Type : [
text/html
],
Content-Length : [
186
],
Server : [
nginx
],
Date : [
Thu, 05 Aug 2021 05:47:33 GMT
]
} }}}}
这是因为AFN网络请求返回数据格式为json,提示这个错误是因为返回数据非json格式。
解决办法:
首先检查一下网络请求方法中是否有这句代码
//设置返回数据格式为JSON
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
没有的话,加上就行