curl 命令将压缩后的 POST 正文发送到 apache 服务器 [英] curl command a gzipped POST body to an apache server

查看:35
本文介绍了curl 命令将压缩后的 POST 正文发送到 apache 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 apache 2.2 服务器上正确激活 mod_deflate 后,我试图通过 curl 命令行发送一个压缩的正文.

With mod_deflate properly activated on my apache 2.2 server, I am trying to send a gzipped body via curl command line.

我看过的所有教程都说要添加 -H'Content-Encoding: gzip' 和 gzip 我的正文文件,但是这失败了:

All tutorials I have seen say to add -H'Content-Encoding: gzip' and gzip my body file, however this fails:

echo '{ "mydummy" : "json" }' > body
gzip body
curl -v -i http://localhost/mymodule -H'Content-Encoding: gzip' --data-binary @body.gz 

我的 apache 模块收到 0 个字节

My apache module receives 0 bytes

在我的 apache error.log 中,如果 LogLevel 设置为调试,我得到:
[Thu Jun 01 14:29:03 2017] [debug] mod_deflate.c(900): [client 127.0.0.1] 无法膨胀输入:无法处理 deflate 标志

And in my apache error.log if LogLevel is set to debug I get:
[Thu Jun 01 14:29:03 2017] [debug] mod_deflate.c(900): [client 127.0.0.1] Failed to inflate input: cannot handle deflate flags

推荐答案

问题是 mod_deflate 不喜欢这里显示的 gzip 标头:

The thing is that mod_deflate does not like the gzip header shown here:

hexdump -C body.gz
00000000  1f 8b 08 08 20 08 30 59  00 03 62 6f 64 79 00 ab  |.... .0Y..body..|
00000010  56 50 ca ad 4c 29 cd cd  ad 54 52 b0 52 50 ca 2a  |VP..L)...TR.RP.*|
00000020  ce cf 53 52 a8 e5 02 00  a6 6a 24 99 17 00 00 00  |..SR.....j$.....|
00000030

解决方案是简单地将它交给 gzip 而不需要中间文件步骤,如果采用流,它不会打印标题并且 apache 会喜欢正文!

The solution is simply to give it to gzip without the intermediate file step, if taking a stream, it will not print the headers and apache will like the body!

echo '{ "mydummy" : "json" }' | gzip > body.gz
curl -v -i http://localhost/mymodule -H'Content-Encoding: gzip' --data-binary @body.gz

这样就可以了,apache 模块接收解压后的字节.

This works, the apache module receives the decompressed bytes.

这里可以看到header区别,gzip文件中不再看到文件名(body):

You can see the header difference here, you no longer see the file name (body) in the gzip file:

hexdump -C body.gz
00000000  1f 8b 08 00 08 0a 30 59  00 03 ab 56 50 ca ad 4c  |......0Y...VP..L|
00000010  29 cd cd ad 54 52 b0 52  50 ca 2a ce cf 53 52 a8  |)...TR.RP.*..SR.|
00000020  e5 02 00 a6 6a 24 99 17  00 00 00                 |....j$.....|
0000002b

这篇关于curl 命令将压缩后的 POST 正文发送到 apache 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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