本文根据 Devhints / httpie 翻译。代码示例及版本范围沿用原文。原文标注更新日期:2020-07-05。
简介
HTTPie 是一个命令行 HTTP 客户端。
参数
$ http POST http://example.com/posts/3 \
Origin:example.com \ # : HTTP headers
name="John Doe" \ # = string
q=="search" \ # == URL parameters (?q=search)
age:=29 \ # := for non-strings
list:='[1,3,4]' \ # := json
file@file.bin \ # @ attach file
token=@token.txt \ # =@ read from file (text)
user:=@user.json # :=@ read from file (json)
表单
$ http --form POST example.com \
name="John Smith" \
cv=@document.txt
原始 JSON
$ echo '{"hello": "world"}' | http POST example.com/post
选项
打印选项
-v, --verbose # same as --print=HhBb --all
-h, --headers # same as --print=h
-b, --body # same as --print=b
--all # print intermediate requests
--print=HhBb # H: request headers
# B: request body
# h: response headers
# b: response body
--pretty=none # all | colors | format
--json | -j # Response is serialized as a JSON object.
身份验证
--session NAME
-a, --auth USER:PASS
--auth-type basic
--auth-type digest
会话 (Session)
--session NAME # store auth and cookies
--session-read-only NAME
下载
-d, --download # like wget
-c, --continue
-o, --output FILE
其他
-F, --follow # follow redirects
--max-redirects N # maximum for --follow
--timeout SECONDS
--verify no # skip SSL verification
--proxy http:http://foo.bar:3128