Restkit加载gzip压缩的json [英] Restkit loading gzipped json

查看:124
本文介绍了Restkit加载gzip压缩的json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RestKit使用RKRequest加载压缩后的JSON:

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

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

,但我收到状态406.使用AsiHttpRequest时,一切正常,响应被解压缩,并且可以使用JSON.当我在服务器上关闭gzip时,RKRequest起作用.

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.

怎么了?我没有办法告诉RKRequest响应将被压缩.有任何想法吗?

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

这很奇怪.有时候我得到

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";
}

有时我得到正确处理的application/gzip.我的问题是为什么我得到"Content-Type" ="text/html; charset = UTF-8";有时. 并且在Safari中打开的相同请求始终会导致gzip响应.

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.

推荐答案

您可以使用HTTP代理(如Charles)发布标头中的内容吗?

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.

确保您的防火墙能够接受POST呼叫.这可能是一个https问题.

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

您可能需要将服务器配置为始终根据扩展名类型以GZIP和DEFLATE返回响应.这是基于此处的( http://betterexplained .com/articles/如何优化带有gzip压缩的网站/).

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/).

示例:

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

您可以在此处找到"mod_deflate"文档( http://httpd .apache.org/docs/2.0/mod/mod_deflate.html )

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

类似的问题

奇怪的"406 not accept"错误

https://serverfault. com/questions/183843/content-length-not-sent-send-when-gzip-compression-enabled-in-apache

请确保您也这样做:

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

或这个

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

这应将标头的值设置为接受"gzip"以对响应进行编码.我注意到了以下github问题:

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

https://github.com/RestKit/RestKit/issues/511

这篇关于Restkit加载gzip压缩的json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆