AFNetWorking error code =-1016 solution, afnetworking-1016

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.