AFNetwork 3.0网络请求常见问题

问题1:Code=3840错误

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=0x17105df10 {Error Domain=com.alamofire.error.serialization.response Code=-1011 "
Request failed: internal server error (500)" UserInfo={com.alamofire.serialization.response.error.
response=<NSHTTPURLResponse: 0x170622420> { URL: http://syspd.w-oasis.com/urcarAppRmiServlet } { status code: 500, headers {
    Server = Apache-Coyote/1.1,
    Content-Type = text/html;charset=utf-8,
    Set-Cookie = JSESSIONID=4D96EDA3BF1417BA495D6920EBE44CC7; Path=/; HttpOnly,
    Content-Language = en,
    Vary = Accept-Encoding,
    Date = Fri, 14 Oct 2016 07:27:36 GMT,
    Content-Encoding = gzip,
    Content-Length = 848,
    Connection = close
} }, 

解决办法:

//设置请求格式
manager.requestSerializer = [AFJSONRequestSerializer serializer];

//设置返回格式
manager.responseSerializer = [AFHTTPResponseSerializer serializer];

问题2:Code=-1016 错误

Error Domain=com.alamofire.error.serialization.response Code=-1016 
"Request failed: unacceptable content-type: text/plain" 
UserInfo={com.alamofire.serialization.response.error.
response=<NSHTTPURLResponse: 0x174227f20> { URL: http://syspd.w-oasis.com/urcarAppRmiServlet } 
{ status code: 200, headers {
    Keep-Alive = timeout=5, max=100,
    Content-Length = 205,
    Connection = Keep-Alive,
    Server = Apache-Coyote/1.1,
    Date = Fri, 14 Oct 2016 07:31:16 GMT
} }

问题3:code: 503

 { status code: 503, headers {
    Cache-Control = must-revalidate,no-cache,no-store;
    Content-Type = text/html;charset=ISO-8859-1;
    Content-Length = 925;
    Server = Charles;
    Proxy-Connection = Close;
}

解决办法:可能是断网了,请重新连接!😄

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容