AFNetworking 使用
Code=3840 和 Code=-1011 问题
使用AFNetworking进行POST请求
网络解析的时候,我们会遇到解析报错问题,报错如下:
1 | 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=0x7fd7bad02080 {Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fd7bd1c9250> |
我们查看响应头内容中,发现:"Content-Type" = "text/html;charset=utf-8";
,那么我们要使用二进制的解析方式进行解析,同时也不要设置什么接受格式;
1 | NSURLSessionConfiguration *configuratio = [NSURLSessionConfiguration defaultSessionConfiguration]; |
如果设置[m_request setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
后,可能会报错:
1 | Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" |