我正在使用httpie对这个文件位置发出HEAD请求:
$ http HEAD https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb
HTTP/1.1 302 Moved Temporarily
Connection: keep-alive
Content-Length: 169
Content-Type: text/html
Date: Mon, 09 Sep 2019 14:55:56 GMT
Location: https://dbeaver.io/files/6.2.0/dbeaver-ce_6.2.0_amd64.deb
Server: nginx/1.4.6 (Ubuntu)
我只对Location
标头感兴趣,因为我想将其值存储在文件中以查看目标是否已更新。
我试过了:
http HEAD https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb
| grep Location
| sed "s/Location: //"
然而,这会产生空洞的回应。
我假设输出到stderr
而不是stdout
,尽管我真的不想为此将stdout
和stderr
结合起来。
我宁愿直接使用http
命令寻找解决方案。
您缺少--header
选项:
http HEAD https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb
--headers
| grep Location
| sed "s/Location: //"
在撰写本文时,将打印:
https://dbeaver.io/files/6.2.0/dbeaver-ce_6.2.0_amd64.deb
此外,你认为httpie会重定向到stderr
的假设也是错误的。相反,它归结为自动更改--print
选项的默认行为。如果httpie
是管道,它会发生变化!
--print WHAT, -p WHAT
String specifying what the output should contain:
'H' request headers
'B' request body
'h' response headers
'b' response body
The default behaviour is 'hb' (i.e., the response headers and body
is printed), if standard output is not redirected. If the output is piped
to another program or to a file, then only the response body is printed
by default.
--header
/-h
选项只是--print=h
的快捷方式。