OSDN Git Service

Regular updates
[twpd/master.git] / httpie.md
1 ---
2 title: httpie
3 category: CLI
4 layout: 2017/sheet
5 weight: -3
6 updated: 2020-07-05
7 description: |
8   $ http POST http://example.com name="John" Host:example.com — JSON, cookies, files, auth, and other httpie examples.
9 ---
10
11 ### Introduction
12 {: .-intro}
13
14 [HTTPie](https://httpie.org/) is a command-line HTTP client.
15
16 - [HTTPie website](https://httpie.org/) _(httpie.org)_
17 - [HTTPie documentation](https://httpie.org/docs) _(httpie.org)_
18 - [Try it online](https://httpie.org/run) _(httpie.org)_
19
20 ### Parameters
21
22 ```bash
23 $ http POST http://example.com/posts/3 \
24     Origin:example.com \  # :   HTTP headers
25     name="John Doe" \     # =   string
26     q=="search" \         # ==  URL parameters (?q=search)
27     age:=29 \             # :=  for non-strings
28     list:='[1,3,4]' \     # :=  json
29     file@file.bin \       # @   attach file
30     token=@token.txt \    # =@  read from file (text)
31     user:=@user.json      # :=@ read from file (json)
32 ```
33
34 ### Forms
35
36 ```bash
37 $ http --form POST example.com \
38     name="John Smith" \
39     cv=@document.txt
40 ```
41
42 ### Raw JSON
43
44 ```bash
45 $ echo '{"hello": "world"}' | http POST example.com/post
46 ```
47
48 ### Options
49
50 #### Printing options
51
52 ```bash
53 -v, --verbose            # same as --print=HhBb --all
54 -h, --headers            # same as --print=h
55 -b, --body               # same as --print=b
56     --all                # print intermediate requests
57     --print=HhBb         # H: request headers
58                          # B: request body
59                          # h: response headers
60                          # b: response body
61     --pretty=none        # all | colors | format
62     --json | -j          # Response is serialized as a JSON object.
63 ```
64
65 #### Authentication
66
67 ```bash
68     --session NAME
69 -a, --auth USER:PASS
70     --auth-type basic
71     --auth-type digest
72 ```
73
74 #### Session
75
76 ```bash
77     --session NAME       # store auth and cookies
78     --session-read-only NAME
79 ```
80
81 #### Downloading
82
83 ```bash
84 -d, --download           # like wget
85 -c, --continue
86 -o, --output FILE
87 ```
88
89 #### Others
90
91 ```bash
92 -F, --follow             # follow redirects
93     --max-redirects N    # maximum for --follow
94     --timeout SECONDS
95     --verify no          # skip SSL verification
96     --proxy http:http://foo.bar:3128
97 ```
98
99 ### References
100
101 * <https://github.com/jakubroztocil/httpie>