报错类似:
2015-12-09 15:58:03.062 Carloans[14328:2300485] Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fe5ac728b50> { URL: http://api.lizicaifu.com/api.php?s=/Member/index.html&token=e0e9162086738e15a066daed1ff94baa&user_token=c8d353b0008099ba72fbcfea0b16f1c3 } { status code: 200, headers {
"Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; Connection = "keep-alive"; "Content-Encoding" = gzip; "Content-Type" = "text/html"; Date = "Wed, 09 Dec 2015 07:57:58 GMT"; Expires = "Thu, 19 Nov 1981 08:52:00 GMT"; Pragma = "no-cache"; Server = nginx; "Transfer-Encoding" = Identity; "X-Powered-By" = "PHP/5.5.29";} }, NSErrorFailingURLKey=http://api.lizicaifu.com/api.php?s=/Member/index.html&token=e0e9162086738e15a066daed1ff94baa&user_token=c8d353b0008099ba72fbcfea0b16f1c3, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a2d33 2c22696e 666f223a 225c7538 6266375c 75393163 645c7536 3562305c 75373637 625c7535 66353522 2c226669 72737422 3a6e756c 6c2c226c 61737422 3a224144 38444444 45322d41 4642312d 34343130 2d423536 452d3634 46434331 32303241 4134227d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}1.修改内部文件
AFURLResponseSerialization.m 这个文件找到这句话self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; 然后把 text/html 加进去就可以了! 试试,我就是这么干的。
2.在外面修改
2.0已经对各种方法做了优化,也不需要用AFJSONRequestOperation,2.0已经自带JSON解析。
你可以用AFHTTPRequestOperationManager解决一切问题,遇到你的这个问题,你可以像这么写: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];//设置相应内容类型 [manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; 2.0会对返回的JSON或者XML自动解析为字典的