curl命令将zip压缩的POST正文发送到apache服务器 [英] curl command a gzipped POST body to an apache server
问题描述
在我的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设置为debug,我得到:
[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
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.
您可以在此处看到标头的区别,您不再在gzip文件中看到文件名(正文):
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命令将zip压缩的POST正文发送到apache服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!