AFN failed:unacceptable Content-type:text/plain, com.alamofire.serialization

Source: Internet
Author: User

When using AFN for network requests or uploading files, the response message cannot be accepted and parsed. will report the error as above.

That's because the server response format is not supported by AFN, not AFN, but the server returns format is not normal.

Here are two solutions:

1. The Fucking solution

AFURLRESPONSESERIALIZATION.M file

223 lines:

Self.acceptablecontenttypes = [nssetsetwithobjects:@ "Application/json", @ "text/html", @ " Text/json ", @" Text/javascript ", nil];

In addition to the bold part, it is actually adding a data format returned by the server.

2. Suggested Solutions

Manager. Serializer. acceptablecontenttypes = [nsset setwithobject:@ "Text/plain"];

2 The most direct benefit compared to 1 is that it is simple and gentle and does not modify the code of the third-party framework, even if the upgrade will not cause problems

Error message ****************

Error getting server response error=error domain=com.alamofire.error.serialization.response code=-1016 "Request failed:unacceptable Content-type:text/html "userinfo=0x7fdfd8729680 {com.alamofire.serialization.response.error.response= {url:http:/ /172.16.1.31:7001/itom/getwork} {Status code:200, headers {

"Cache-control" = "No-cache";

"Content-type" = "text/html;charset=utf-8";

Date = "Mon, 03:13:16 GMT";

"Transfer-encoding" = Identity;

"X-powered-by" = "servlet/2.5 jsp/2.1";

}}, Nserrorfailingurlkey=http://172.16.1.31:7001/itom/getwork, com.alamofire.serialization.response.error.data= <5b7b2273 74617475 73223a22 73756363 65737322 2c226d73 67223a22 e799bbe9 9986e688 90e58a9f 227d5d>, NSLocalizedDesc Ription=request failed:unacceptable content-type: text/html or Text/plain}

AFN failed:unacceptable Content-type:text/plain, com.alamofire.serialization

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.