AFNetWorking error code =-1016 solution, afnetworking-1016
The error is similar to the following:
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 = c8d0000b0008099ba72fbcfea0b16f1c3} {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 = c8d0000b0008099ba72fbcfea0b16f1c3, com. alamofire. serialization. response. error. data = <7b227374 61747573 223a2d33 2c22696e 0000000000000000000000000000000000000000000000000000000000000000000000000000000075393163 45322d41 4642312d 75373637 00000000000066353522 limit>, NSLocalizedDescription = Request failed: unacceptable content-type: text/html}
1. modify internal files
AFURLResponseSerialization. m this file finds this sentence self. acceptableContentTypes = [NSSet setWithObjects: @ "application/json", @ "text/json", @ "text/javascript", nil]; then you can add text/html! That's what I did.
2. Modify it outside
2.0 has been optimized for various methods, and AFJSONRequestOperation is not required. 2.0 already comes with JSON parsing.
You can use AFHTTPRequestOperationManager to solve all problems. When you encounter this problem, you can write it like this:
AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager];
Manager. responseSerializer. acceptableContentTypes = [NSSet setWithObject: @ "text/html"]; // you can specify the content type.
[Manager POST: url parameters: parameters success: ^ (AFHTTPRequestOperation * operation, id responseObject ){
} Failure: ^ (AFHTTPRequestOperation * operation, NSError * error ){
}];
2.0 the returned JSON or XML is automatically parsed as Dictionary