压缩浏览器发送的HTTP Post数据 [英] Compressing HTTP Post Data sent from browser

查看:734
本文介绍了压缩浏览器发送的HTTP Post数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Javascript将压缩的POST数据发送到我控制的服务器。有没有办法让HTTP层处理压缩。

I want to send a compressed POST data with Javascript to a server I control. Is there any way to let the HTTP layer deal with the compression.

我正在发送JSON。如果我将内容类型设置为GZIP / deflate,浏览器会自动压缩它,然后Apache使用deflate mod自动解压缩它,这样我的应用程序就不必考虑被压缩的数据了吗?

I'm sending JSON. If I set the content type to GZIP/deflate will the browser automatically compress it and then Apache with the deflate mod automatically decompress it so my application doesn't have to think about the data being compressed at all?

我知道它可以反过来但是以任何方式使它以这种方式工作吗?

I know it can work the other way around but any way to make it work this way?

推荐答案

浏览器会自动为您的数据进行gzip编码吗?简短的回答是否定的。

Will the browser automatically gzip-encode your data for you? The short answer is no.

长期的答案是,一些用户代理可以做这样的事情,但你绝对不能依赖在上面。 apache mod_deflate docs状态:

The long answer is that some user-agents can do things like this, but you definitely can't rely on it. The apache mod_deflate docs state:


一些特殊应用程序实际上支持请求压缩,例如一些WebDAV客户端。

some special applications actually do support request compression, for instance some WebDAV clients.

所以,不,那不行。您需要自己生成适当的HTTP请求消息。在这种情况下,适当的标题是 Content-Encoding:gzip 和NOT Content-Type:因为内容本身是 application / json ,您只是想编码HTTP请求消息的实体主体以进行传输。

So, no, that's not going to work. You'll need to generate the appropriate HTTP request message yourself. The appropriate header in this case is Content-Encoding: gzip and NOT Content-Type: because the content itself is application/json, you're just looking to encode the entity body of your HTTP request message for transport.

注意您还需要添加相应的 Content-Length:标头,指定压缩后消息实体主体的大小(以字节为单位)-OR-使用<$ c $发送HTTP消息c> Transfer-Encoding:chunked 并放弃内容长度规范。

Note that you need to also add the appropriate Content-Length: header specifying the size in bytes of the message entity body after compression -OR- send your HTTP message using Transfer-Encoding: chunked and forego the content-length specification.

在接收端,你可以 指示 mod_deflate 使用输入过滤器以解压缩信息:

On the receiving end, you can instruct mod_deflate to use an input filter to decompress the information:

<Location /dav-area>
SetInputFilter DEFLATE
</Location>

如果您只接收几个资源的压缩邮件正文,这有点沉重。相反,您应该只使用客户端脚本来检查 Content-Encoding:gzip 标头并手动解压缩请求正文。如何做到这一点,比如PHP,完全是另一个问题。如果您需要详细信息,请发布另一个问题。

This is a bit heavy handed if you're only receiving compressed message bodies for a couple of resources. Instead, you should probably just use the client-side script to check for the Content-Encoding: gzip header and decompress the request body manually. How to do this in say, PHP, is another question entirely. If you need details for that you should post another question.

这篇关于压缩浏览器发送的HTTP Post数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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