有没有办法让curl解压缩响应而不在请求中发送Accept标头?

Jun*_*awa 49 curl gzip

Is there any way to get curl to decompress a response without sending the Accept-encoding headers in the request?

I'm trying to debug an issue where the order of the Accept-encoding headers may be relevant, but I also need to know what the response is. If I just send -H 'Accept-encoding: gzip and the server gzips the response, curl won't decompress it.

Fat*_*ror 83

可能最容易做的就是用gunzip它来做:

curl -sH 'Accept-encoding: gzip' http://example.com/ | gunzip -
Run Code Online (Sandbox Code Playgroud)

或者还有--compressed,curl它将解压缩(我相信),因为它知道响应被压缩.但是,不确定这是否符合您的需求.

  • @ Jun-DaiBates-Kobashigawa您可以使用-D将标头转储到文件,例如`-D headers.txt`,它会将它们保存到带外文件中,这样就不会搞砸你的gzip编码. (3认同)

tha*_*kis 17

curl --compressed http://example.com 将要求压缩压缩的数据并在将其写入磁盘之前将其解压缩。