When using AFNetworking in iOS, the following error occurs: Request failed: unacceptable content-type: text/html, and iosafnetworking.

Source: Internet
Author: User

When using AFNetworking in iOS, the following error occurs: Request failed: unacceptable content-type: text/html, and iosafnetworking.

 

Error Log:

Error Domain = com. alamofire. error. serialization. response Code =-1016 "Request failed: unacceptable content-type: text/html" UserInfo = {com. alamofire. serialization. response. error. response = <NSHTTPURLResponse: 0x7f999be478d0> {URL: myUrlXXXXXX} {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; charsets = UTF-8 ";

Date = "Tue, 24 Nov 2015 09:06:04 GMT ";

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

Pragma = "no-cache ";

Server = "nginx/1.1.19 ";

"Set-Cookie" = "PHPSESSID = qdvtek1k91oeva2u8fats39l93; path = /";

"Transfer-Encoding" = Identity;

"X-Powered-By" = "PHP/5.3.10-1ubuntu3. 21 ";

}, NSErrorFailingURLKey = http:URL: myUrlXXXXXX, Com. alamofire. serialization. response. error. data = <0000000000000000000070000223a 000075706c6f 61645f75 0000c223a 22657272 00005c2f7777 772e7467 7370792e 0000000022687474 000000000000000000000000000000007869616e 000067227d>, NSLocalizedDescription = Request failed: unacceptable content-type: text/html}

 

Cause:

Unacceptable content type"Text/html"

Solution:

About 222 lines in AFJSONResponseSerializer. m

Put this sentence: self. acceptableContentTypes = [NSSet setWithObjects: @ "application/json", @ "text/json", @ "text/javascript", nil];

To:

Self. acceptableContentTypes = [NSSet setWithObjects: @ "application/json", @ "text/json", @ "text/javascript", @ "text/html", nil];

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.