簡體   English   中英

如何在bash中管道httpie請求的標頭信息?

[英]How to pipe header information of a httpie request in bash?

我正在使用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 ,盡管我真的不想為此組合stdoutstderr

我寧願直接使用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的快捷方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM