netshark1000
netshark1000

Reputation: 7403

Restkit loading gzipped json

I'm using RestKit to load a gzipped JSON with RKRequest:

RKRequest* request = [[RKClient sharedClient] requestWithResourcePath:urlString delegate:self];
[request send];

but I receive a status 406. When using AsiHttpRequest everything works, the response gets unzipped and I can work with the JSON. When I turn off gzip on server the RKRequest works.

What is wrong? I found no way to tell RKRequest, that the response will be zipped. Any ideas?

EDIT:

It is strange. Sometimes I get

Headers: {
    Connection = "Keep-Alive";
    "Content-Length" = 14;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Fri, 16 Mar 2012 13:44:16 GMT";
    "Keep-Alive" = "timeout=2, max=500";
    Server = Apache;
    "X-Powered-By" = "Servlet/2.5 JSP/2.1";
}

and sometimes I get application/gzip which is handled correct. My problem is why I get "Content-Type" = "text/html; charset=UTF-8"; sometimes. And the same request opened in Safari results in a gzip-response always.

Upvotes: 1

Views: 1762

Answers (1)

Dominic Tancredi
Dominic Tancredi

Reputation: 42332

Can you post what's in your headers using an HTTP Proxy (like Charles)?

You may need to modify your "request headers" in the post call.

Make sure your firewall is able to accept POST calls. This might be an https issue.

EDIT:

You may need to configure your server to always return the response as a GZIP and DEFLATE based on the extension type. This is based on here (http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/).

Example:

# compress json format in .htaccess (for apache servers):
AddOutputFilterByType DEFLATE application/json

You can find the 'mod_deflate' documentation here (http://httpd.apache.org/docs/2.0/mod/mod_deflate.html)

If you can post the outgoing headers, that would also be useful, as they should include:

Accept-Encoding: gzip, deflate

Similar issues

EDIT:

Make sure you also do this:

[[RKClient sharedClient] setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];

or this

[[RKClient sharedClient] setValue:@"gzip, deflate" forHTTPHeaderField:@"Accept-Encoding"];

This should set the value of your header to accept "gzip" for encoding the response. I noticed these github issues:

Upvotes: 2

Related Questions