Httpie: httpはbashループ内では機能しません

作成日 2013年11月23日  ·  3コメント  ·  ソース: httpie/httpie

Looks like a leackage.

I have this file, links.txt:
www.google.com?q=1  
www.google.com?q=2  
www.google.com?q=3  
www.google.com?q=4  


Running this:
$ cat links.txt | while read line; do http --print BHhb GET $line; done

Expected result:
4 http calls, one for each line on the file.

Actual:
1 request executed to the first url in the file and request body having the other 3 lines.

GET /?q=1 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 63
Content-Type: application/json; charset=utf-8
Host: www.google.com
User-Agent: HTTPie/0.6.0

www.google.com?q=2
www.google.com?q=3
www.google.com?q=4

HTTP/1.0 400 Bad Request
Content-Length: 925
Content-Type: text/html; charset=UTF-8
Date: Sat, 23 Nov 2013 19:48:51 GMT
Server: GFE/2.0

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 400 (Bad Request)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}<strong i="5">@media</strong> screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
  </style>
  <a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
  <p><b>400.</b> <ins>That’s an error.</ins>
  <p>Your client has issued a malformed or illegal request.  <ins>That’s all we know.</ins>



Running same script with curl instead works as expected.


cheers!

最も参考になるコメント

これは、HTTPieがリダイレクトされた場合(ループ内にある場合)、デフォルトでSTDINを読み取るためです。

それを取り除くには複数の方法があります:

  • 最良の方法は、 --ignore-stdin (この問題を正確に解決するために存在します)を使用することです。
cat links.txt | while read url; do 
        http --ignore-stdin --verbose $url
done
  • または、 STDINをターミナルに戻します。
cat links.txt | while read url; do
        http --verbose $url < /dev/tty
done
  • または、そもそもSTDINをリダイレクトしないでください(ただし、スペースに注意してください)。
for url in `cat links.txt`; do 
        http --verbose $url
done

#150も参照してください。

全てのコメント3件

これは、HTTPieがリダイレクトされた場合(ループ内にある場合)、デフォルトでSTDINを読み取るためです。

それを取り除くには複数の方法があります:

  • 最良の方法は、 --ignore-stdin (この問題を正確に解決するために存在します)を使用することです。
cat links.txt | while read url; do 
        http --ignore-stdin --verbose $url
done
  • または、 STDINをターミナルに戻します。
cat links.txt | while read url; do
        http --verbose $url < /dev/tty
done
  • または、そもそもSTDINをリダイレクトしないでください(ただし、スペースに注意してください)。
for url in `cat links.txt`; do 
        http --verbose $url
done

#150も参照してください。

--ignore-stdinは私が探していたものです。 インストールされているものを更新する必要がありました
バージョンですが、現在は期待どおりに動作しているようです。
私はhttpieが大好きですが、この小さなことで私はいつか理解することができました...

非常に速い応答をありがとう。
乾杯!

2013年11月23日土曜日午後4時17分、 JakubRoztočilnotifications @ github.com書き込み:

クローズ#181https ://github.com/jkbr/httpie/issues/181。


このメールに直接返信するか、 GitHubで表示してくださいhttps://github.com/jkbr/httpie/issues/181

Filipe Gomes Esperandio

Gtalk: [email protected]
Skype:filipesperandio
Google Voice:+1 650 701 7057

こんにちは、私は--ignore-stdinを介して解決された同様の問題を抱えていましたが、私のコンテキストは少し異なります:

./run.sh http https://base-url/endpoint\?attributes=all\&nested_attribbutes\=all Authorization:Bearer\ bf54b184d7729ac9bfffb576782e2a1d3cd7bd76 Content-Type:application/json Accept:\ \*/\* -h

私はHTTP/1.1 422 Unprocessable Entityを手に入れていました

run.shスクリプトは次のようになります: seq 5 | xargs -I {} -n1 "$@"

--ignore-stdinを追加すると問題が修正されますが、 STDINからのリクエストを読んでいません。 この文脈でどのように機能するか説明していただけますか?

このページは役に立ちましたか?
0 / 5 - 0 評価