2

Here is my problem. I have a server that gives me a response in JSON text. However the header content type is 'text/html' and I can't change it.

I need to proccess this response in my IOS app. I am using RESTKIT to make the request and handle the response, but RESIKIT tells me that content type expected is 'application/json' but gets 'text/html'.

Again, I cannot change the header content type since the server is a third party system.

My question is if it is possible and if so how do I get RESTKIT to read this 'text/html' response as of it was a 'application/json' response.

I looked around for a solution and everyone keep saying to ad this line of code.

[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/html"];

And I did, but I am still having the same problem. What am I missing?

Terrick Mansur
  • 147
  • 1
  • 10

1 Answers1

3

As you say, you do need to teach RestKit to treat a response of mime type text/html and JSON, to do that call:

[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/html"];

somewhere in your setup code. But, you also need to tell RestKit that text/html is a valid response mime type, to do that call:

[self.objectManager setAcceptHeaderWithMIMEType:@"text/html"];

on your object manager instance.

Wain
  • 118,658
  • 15
  • 128
  • 151