ios-Modify afnetworking source file to receive Text/plain method

Source: Internet
Author: User

 ios-Modify afnetworking source file to receive Text/plain methodyou may encounter the following error when using afnetworking:

{Status code:200, headers {

"Content-length" =;

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

Date = "Thu, 10:37:50 GMT";

Server = "apache-coyote/1.1";

"Set-cookie" = "JSESSIONID=C0DFED60A154557F8386E62AB2A066CE; Path=/fhjrdt ";

}}, Nslocalizeddescription=request failed:unacceptable Content-type:text/plain}

At this time need to modify afnetworking can receive Content-type, go to afnetworking Source code directory to find AFURLRESPONSESERIALIZATION.M file will inside the code:

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

Modified to:

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

-----------------------Dividing line-----------------------------

Although the above method can be achieved, but I have recently only to see that the next worst.

The better way is this:

The person who is experiencing this problem is probably not adding a paragraph in the code: Manager.responseserializer = [Afhttpresponseserializerserializer];

The sample code is as follows:

NSString *urlstr [email protected] "http://xxxx";

Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanagermanager];

Manager.responseserializer = [Afhttpresponseserializerserializer]; It is important to get rid of the error, but not yet understand more detailed reasons

[Managerget:urlstr parameters:@{@ "username": @ "xxx", @ "password": @ "xxx"}success:^ (afhttprequestoperation * Operation,id responseobject) {

Parse success

NSLog (@ "JSON:%@", responseobject);

}failure:^ (afhttprequestoperation *operation,nserror *error) {

Parse failed

NSLog (@ "error:++++%@", error.localizeddescription);

}];}

ios-Modify afnetworking source file to receive Text/plain methods

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.