Odo
Odo

Reputation: 209

Ignoring REST Service Content-Type for JSON with AFJSONRequestOperation?

is there a way to ignore the return content type from a Rest Service for a AFJSONRequestOperation ? One of the services i use returns application/text and will not be fixed before the next major release. At the moment i use AFJSONRequestOperation and it fails because of this.

I tried to use:

AFHTTPClient *afClient  = [[AFHTTPClient alloc] initWithBaseURL:url];
[afClient setDefaultHeader:@"Accept" value:@"application/json"];

But this do not work.

Any other way ?

Thanks, Oliver

Upvotes: 0

Views: 156

Answers (1)

Bart Jacobs
Bart Jacobs

Reputation: 9082

One possible solution for dealing with situations like this is calling addAcceptableContentTypes: on the AFHTTPRequestOperation subclass that you are using. In your specific situation, add the following snippet to the initWithBaseURL method of your AFHTTPClient subclass.

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObjects:@"application/text", nil]];

You can read more about addAcceptableContentTypes: in the documentation of AFNetworking.

Upvotes: 1

Related Questions