bash - 如何在 bash 中传输 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)
我只对Location
标头感兴趣,因为我想将其值存储在文件中以查看目标是否已更新。
我试过了:
http HEAD https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb \
| grep Location \
| sed "s/Location: //"
但这会产生空洞的响应。
我假设输出转到stderr
而不是stdout
,尽管我真的不想为此组合stdout
and 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
推荐阅读
- postgresql - 如何在 PostgresSQL 10 中备份分区表
- autocomplete - 如何更改 Visual Studio 代码自动更正花括号的方式?
- python - 通过 TensorFlow 消费大数据
- docker - 在 Kubernetes 集群中部署内部 docker 镜像
- html - 在 html 中显示多张图片,而无需为每一张都写一个标签
- dart - Flutter:覆盖触发重建中的文本字段
- javascript - 如何使用 javascript 显示/隐藏复数 div?
- java - 如果在 Java 中使用原始类型,如何强制编译错误以强制泛型类型参数?
- node.js - 如何在 Node.js 中正确调用 AWS.CloudFront.Signer?
- node.js - 为什么将 ESM 转换为 CommonJS 不是简单的查找和替换?