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