ios Request failed: unacceptable content-type: text/html"

weixin_33724059發表於2016-09-29

Printing description of error:Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response={ URL: http://120.24.45.67/user/login } { status code: 200, headers {

"Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-cache";

Connection = "Keep-Alive";

"Content-Encoding" = gzip;

"Content-Length" = 117;

"Content-Type" = "text/html; charset=UTF-8";

Date = "Thu, 29 Sep 2016 14:42:45 GMT";

Expires = "Thu, 19 Nov 1981 08:52:00 GMT";

"Keep-Alive" = "timeout=5, max=100";

Pragma = "no-cache";

Server = "Apache/2.4.7 (Ubuntu)";

"Set-Cookie" = "PHPSESSID=mjbe8tpshmi5ru8e78v9ep8125; path=/, laravel_session=eyJpdiI6IkVkWjRuT2pybWFneEh2b2JNaTh6Zmc9PSIsInZhbHVlIjoiSlwvRHkxbUZmNG5BVnlEMjBVMm1pU1hHU2ljSk4zeHpZMDdMOGV1clRnRmRDVlNZc2dHTVRDQkNtVDFMeGtqMTc3dE5CNHRMcVlwZnVodGNHYUFPdmpnPT0iLCJtYWMiOiI3YTAyMmIyYThiNjZkZDM3Yzc4MjAxYTVlMzM0YjczZmJhOTFiMDQxYzAyZWMyM2NkZmQwYjMwZjkwMDA4ZDEzIn0%3D; expires=Thu, 29-Sep-2016 16:42:45 GMT; Max-Age=7200; path=/; httponly";

Vary = "Accept-Encoding";

"X-Powered-By" = "PHP/5.5.9-1ubuntu4.18";

} }, NSErrorFailingURLKey=http://120.24.45.67/user/login, com.alamofire.serialization.response.error.data=<7b22636f 6465223a 22353030 222c226d 7367223a 22e69caa e68ea5e6 94b6e588 b0e695b0 e68dae22 2c22696e 666f223a 7b227265 73756c74 223a2230 222c2275 6964223a 22222c22 6e69636b 6e616d65 223a2222 2c226176 61746172 223a2222 2c226163 63657373 746f6b65 6e223a22 227d7d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

仔細看下報錯資訊,大致意思就是在接收資料的時候缺少“text/html”這個內容型別。

解決辦法就是在AFNetWorking的responseSerializer裡面增加”text/html“這個內容型別。

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

manager.responseSerializer = [AFJSONResponseSerializer new];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];

這樣就大功告成了~但是一定要注意,responseSerializer使用之前一定要new一次,不然配置的東西無效。



也可以參考:

http://www.jianshu.com/p/a89f99c26956

相關文章