LoginSignup
0

posted at

updated at

HTTPieとcURLのコマンド比較

CLIでのHTTPクライアントコマンドとしては cURL が有名だが、 最近HTTPie を知った。
HTTPPieは、HTTP専用なので、コマンドがわかりやすい。かつ、出力がカラーリングされるので、結果が見やすい。

コマンドの比較を記す。

get

httpie

http https://www.example.com

curl と違い、レスポンスボディとともに、リクエストヘッダが表示される。レスポンスボディのみを表示したい場合は、 --print b をつける。

curl

curl https://www.example.com

HTTP proxy利用

httpie
--proxy PROTOCOL:PROXY_URL

http --proxy http:http://proxy.example.com:8080 https://www.example.com

curl
--proxy PROXY_URL

curl --proxy http://proxy.example.com:8080 https://www.example.com

Redirect

どちらもデフォルトでは、リダイレクトに従わない。

httpie
--follow or -f

http --follow https://www.example.com

curl
--location or -l

curl --location https://www.example.com

リクエスト、レスポンスヘッダー表示

httpie

--print で指定

  • h: レスポンスヘッダ
  • H: リクエストヘッダ
  • b: レスポンスボディ
  • B: リクエストボディ
# レスポンスヘッダ、リクエストヘッダ、レスポンスボディを表示
http --print hHb https://www.example.com

curl

curl -v https://www.example.com

レスポンスボディのみをファイルに保存

httpie
--download
--output <filename> で、出力ファイルを指定。
--print hHを指定して、リクエストヘッダ・レスポンスヘッダを出力していたとしても、--download をつけることで、レスポンスボディのみが ファイルに保存される。

http --download --output output.txt https://www.example.com

--print hHを指定して、リクエストヘッダ・レスポンスヘッダを出力していたとしても、--download をつけることで、レスポンスボディのみが ファイルに保存される。

curl
--output <filename>

curl --output output.txt https://www.example.com

SSL/TLSのverifyをスキップする

httpie

--verify no

http --verify no https://www.example.com

curl
--insecure or -k

curl --insecure https://www.example.com

リクエストヘッダの追加

リクエストヘッダに、foo:foo1, bar:bar1 を追加

httpie

http https://www.example.com  foo:foo1 bar:bar1

curl

curl -H foo:foo1 -H bar:bar1  https://www.example.com

パラメータの追加

https://www.example.com?foo=fooValue&bar=barValue のように送りたい

httpie
== で指定する

http https://www.example.com foo==fooValue bar==barValue

# もちろん、このようにしてもよい。 ? や & は shellとして特別な意味を持つので、""で囲む。
http "https://www.example.com?foo=fooValue&bar=barValue"

curl

curl -G -d foo=fooValue -d bar=barValue   https://www.example.com

# これでもよい
http "https://www.example.com?foo=fooValue&bar=barValue"

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0