0

我正在使用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,尽管我真的不想为此组合stdoutand stderr

我宁愿直接使用http命令寻找解决方案。

4

1 回答 1

1

您缺少以下--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

于 2019-09-09T15:26:19.030 回答