語法:json
http [--json] [--form] [--pretty {all,colors,format,none}] [--style STYLE] [--print WHAT] [--headers] [--body] [--verbose] [--all] [--history-print WHAT] [--stream] [--output FILE] [--download] [--continue] [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH] [--auth USER[:PASS]] [--auth-type {basic,digest}] [--proxy PROTOCOL:PROXY_URL] [--follow] [--max-redirects MAX_REDIRECTS] [--timeout SECONDS] [--check-status] [--verify VERIFY] [--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT] [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version] [--traceback] [--default-scheme DEFAULT_SCHEME] [--debug] [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
簡寫就是:瀏覽器
$ http [flags] [METHOD] URL [ITEM [ITEM]]
METHOD
若是不帶METHOD參數,這默認爲GET(沒有附帶請求參數)或POST(附帶請求參數,默認以json格式傳輸)session
$ http example.org # => GET $ http example.org hello=world # => POST
URL
默認協議爲 http://
,若是主機是localhost
,還能夠以下簡寫:app
$ http :3000 # => http://localhost:3000 $ http :/foo # => http://localhost/foo
另外能夠使用param==value語法像url添加參數,所產生的效果就是瀏覽器中經過&鏈接的參數,注意區分POST方法所使用的param=value語法this
http www.google.com search=='HTTPie logo' tbm==isch
建立更方便https的命令google
alias https='http --default-scheme=https'
Request itemsurl
Item Type | Description | e.g |
---|---|---|
HTTP Headers Name:Value |
Arbitrary HTTP header | X-API-Token:123 |
URL parameters name==value |
Appends the given name/value pair as a query string parameter to the URL. The == separator is used. |
|
Data Fields field=value , field=@file.txt |
Request data fields to be serialized as a JSON object (default), or to be form-encoded (--form, -f ). |
`` |
Raw JSON fields field:=json , field:=@file.json |
Useful when sending JSON and one or more fields need to be a Boolean , Number , nested Object , or an Array |
meals:='["ham","spam"]' or pies:=[1,2,3] (note the quotes). |
Form File Fields field@/dir/file |
Only available with --form, -f . The presence of a file field results in a multipart/form-data request. |
screenshot@~/Pictures/img.png. |
`` | ||
`` | ||
`` | ||
`` |
param=value格式的參數所有會轉換成json格式傳輸,而且value全是字符串spa
http POST httpbin.org/anything name=John email=john@example.org age=26 HTTP/1.1 200 OK Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: * Connection: keep-alive Content-Length: 575 Content-Type: application/json Date: Tue, 05 Dec 2017 05:03:10 GMT Server: meinheld/0.6.1 Via: 1.1 vegur X-Powered-By: Flask X-Processed-Time: 0.000778913497925 { "args": {}, "data": "{\"name\": \"John\", \"email\": \"john@example.org\", \"age\": \"26\"}", "files": {}, "form": {}, "headers": { "Accept": "application/json, */*", "Accept-Encoding": "gzip, deflate", "Connection": "close", "Content-Length": "58", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "HTTPie/0.9.9" }, "json": { "age": "26", "email": "john@example.org", "name": "John" }, "method": "POST", "origin": "183.234.62.33", "url": "http://httpbin.org/anything" }
非字符串字段則使用 :=
分隔符, which allows you to embed raw JSON into the resulting object. Text and raw JSON files can also be embedded into fields using =@ and :=@:debug
/tmp cat addr.json { "home":"home addr", "school":"school addr" } /tmp cat about.txt this is about http POST httpbin.org/anything name=John email=john@example.org \ > age:=29 married:=false hobbies:='["http", "pies"]' \ \ # Raw JSON > about=@about.txt \ # Embed text file > addr:=@addr.json # Embed JSON file HTTP/1.1 200 OK Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: * Connection: keep-alive Content-Length: 915 Content-Type: application/json Date: Tue, 05 Dec 2017 05:10:58 GMT Server: meinheld/0.6.1 Via: 1.1 vegur X-Powered-By: Flask X-Processed-Time: 0.00129795074463 { "args": {}, "data": "{\"name\": \"John\", \"email\": \"john@example.org\", \"age\": 29, \"married\": false, \"hobbies\": [\"http\", \"pies\"], \"about\": \"this is about \\n\", \"addr\": {\"home\": \"home addr\", \"school\": \"school addr\"}}", "files": {}, "form": {}, "headers": { "Accept": "application/json, */*", "Accept-Encoding": "gzip, deflate", "Connection": "close", "Content-Length": "188", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "HTTPie/0.9.9" }, "json": { "about": "this is about \n", "addr": { "home": "home addr", "school": "school addr" }, "age": 29, "email": "john@example.org", "hobbies": [ "http", "pies" ], "married": false, "name": "John" }, "method": "POST", "origin": "183.234.62.33", "url": "http://httpbin.org/anything" }