我编写了一个bash脚本,它使用curl从一个网站输出,并在html输出上做了一堆字符串操作.问题是当我针对返回其输出gzip的网站运行它时.在浏览器中访问该网站工作正常.
当我手动运行curl时,我得到gzipped输出:
$ curl "http://example.com"
Run Code Online (Sandbox Code Playgroud)
这是该特定网站的标题:
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=utf-8
X-Powered-By: PHP/5.2.17
Last-Modified: Sat, 03 Dec 2011 00:07:57 GMT
ETag: "6c38e1154f32dbd9ba211db8ad189b27"
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: must-revalidate
Content-Encoding: gzip
Content-Length: 7796
Date: Sat, 03 Dec 2011 00:46:22 GMT
X-Varnish: 1509870407 1509810501
Age: 504
Via: 1.1 varnish
Connection: keep-alive
X-Cache-Svr: p2137050.pubip.peer1.net
X-Cache: HIT
X-Cache-Hits: 425
Run Code Online (Sandbox Code Playgroud)
我知道返回的数据是gzip压缩的,因为这会返回html,如预期的那样:
$ curl "http://example.com" | gunzip
Run Code Online (Sandbox Code Playgroud)
我不想通过gunzip管道输出,因为脚本在其他站点上按原样运行,并且通过gzip管道将破坏该功能.
一切都空了
有任何想法吗?
Mar*_*tin 237
curl如果设置--compressed标志,将自动解压缩响应:
curl --compressed "http://example.com"
Run Code Online (Sandbox Code Playgroud)
--compressed (HTTP)使用libcurl支持的算法之一请求压缩响应,并保存未压缩的文档.如果使用此选项并且服务器发送不受支持的编码,则curl将报告错误.
gzip很可能是受支持的,但您可以通过在"功能"行中的某个地方运行curl -V并查找libz来检查:
$ curl -V
...
Protocols: ...
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
Run Code Online (Sandbox Code Playgroud)
请注意,这里真的是有问题的网站.如果curl未传递Accept-Encoding: gzip请求标头,则服务器不应发送压缩响应.
| 归档时间: |
|
| 查看次数: |
74591 次 |
| 最近记录: |