[英]How to pipe header information of a httpie request in bash?
I am making a HEAD request against this file location using httpie : 我正在使用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)
I am only interested in the Location
header as I want to store its value in a file to see if it the target was updated. 我只对Location
标头感兴趣,因为我想将其值存储在文件中以查看目标是否已更新。
I tried: 我试过了:
http HEAD https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb \
| grep Location \
| sed "s/Location: //"
yet this yields in an empty response. 但这会产生空的响应。
I assume the output goes to stderr
instead of stdout
, though I don't really want to combine stdout
and stderr
for this. 我假设输出将输出到stderr
而不是stdout
,尽管我真的不想为此组合stdout
和stderr
。
I am rather looking for a solution directly with the http
command. 我宁愿直接使用http
命令寻找解决方案。
You are missing the --header
option: 您缺少--header
选项:
http HEAD https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb \
--headers \
| grep Location \
| sed "s/Location: //"
will as of this writing print: 在撰写本文时将:
https://dbeaver.io/files/6.2.0/dbeaver-ce_6.2.0_amd64.deb
Furthermore, your assumption that httpie would redirect to stderr
is also wrong. 此外,您认为httpie将重定向到stderr
假设也是错误的。 Instead, it boils down to the automatically changing default behavior of the --print
option. 而是归结为--print
选项的自动更改默认行为。 And it changes on the fact if the httpie
was piped! 如果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.
The --header
/ -h
option is merely a shortcut for --print=h
. --header
/ -h
选项仅仅是--print=h
的快捷方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.