Request Failed: Unacceptable Content-Type: Text/Html Using Afnetworking 2.0

Request failed: unacceptable content-type: text/html using AFNetworking 2.0

This means that your server is sending "text/html" instead of the already supported types.
My solution was to add "text/html" to acceptableContentTypes set in AFURLResponseSerialization class. Just search for "acceptableContentTypes" and add @"text/html" to the set manually.

Of course, the ideal solution is to change the type sent from the server, but for that you will have to talk with the server team.

AFNetworking Request failed: unacceptable content-type: text/html

You are receiving HTML response. To diagnose what's going on, it's useful to see what that HTML actually says.

Temporarily change the response serializer to AFHTTPResponseSerializer and then examine the HTML response and it might provide some information that will enlighten you regarding what's wrong with the request. Or you could leave the code alone and observe the exchange with Charles or other similar tool. But the goal is to see why you got a status code of 500 and the HTML a might give you some clues.

Regarding why the request isn't working, it's hard for us to say without seeing the API. The mix of key name styles in the request is suspicious (underscores in some, camelCase in others), but we don't know the API, so it's not clear if that is a problem or not.

Regarding the Content-Type, AFNetworking will do that for you (and will use application/x-www-form-urlencoded, so I don't think that's the issue.

If the API support team isn't familiar with Objective-C/AFNetworking code samples, you might want to observe the request using a tool such as Charles or something like that. Then capture the raw request getting sent and perhaps the API support team can better diagnose the problem without the distraction of the Objective-C/AFNetworking code.

Request Failed: unacceptable content-type: text/html - AFNetworking 2 in Swift

Try this:

manager.responseSerializer.acceptableContentTypes = NSSet(array: ["text/plain", "text/html", "application/json"]) as Set<NSObject>

or even faster:

manager.responseSerializer = [AFHTTPResponseSerializer serializer];



Related Topics



Leave a reply



Submit