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