- 1.今天后台把接口改了添加了一个token值失效的验证,果断出现
错误信息:
-[NetworkEngine doPost:params:handler:errorHandler:]_block_invoke.101 [Line:121]sf = Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/json" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x13f091530> { URL: http://testapp.chekuangxian.com/report/selectCars } { status code: 200, headers {
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "application/json;charset=utf-8";
Date = "Tue, 08 Nov 2016 03:18:52 GMT";
Server = "nginx/1.6.2";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
} }, NSErrorFailingURLKey=http://testapp.chekuangxian.com/report/selectCars, com.alamofire.serialization.response.error.data=<7b227265 74436f64 65223a22 2d31222c 22657272 6f724d73 67223a22 746f6b65 6ee99d9e e6b395e6 8896e8bf 87e69c9f 222c2276 616c7565 223a2222 7d>, NSLocalizedDescription=Request failed: unacceptable content-type: application/json}
- 2.然后就去网上搜索原因:因为我的AFURLResponseSerialization类中是设置大部分类型的
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
没办法就去看了一下后台大哥写的代码,后台返回的类型是application/json,让他改成text/html后就出现了下面的错误
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.}
- 3.最后仔细看了一下,在自己封装的单例类中重新设置了acceptableContentTypes,哎,也可以重新设置使用系统的
sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]