OSDN Git Service

b04235975f555b543b536d06d4c6aeb52950b19c
[twpd/master.git] / curl.md
1 ---
2 title: Curl
3 category: CLI
4 layout: 2017/sheet
5 updated: 2017-09-20
6 ---
7
8 ## Options
9
10 ### Options
11
12 ```bash
13 -o <file>    # --output: write to file
14 -u user:pass # --user: Authentication
15 ```
16
17 ```bash
18 -v           # --verbose
19 -vv          # Even more verbose
20 -s           # --silent
21 ```
22
23 ```bash
24 -I           # --head: headers only
25 ```
26
27 ### Request
28
29 ```bash
30 -X POST          # --request
31 -L               # follow link if page redirects 
32 ```
33
34 ### Data
35
36 ```bash
37 -d 'data'    # --data: HTTP post data, URL encoded (eg, status="Hello")
38 -d @file     # --data via file
39 -G           # --get: send -d data via get
40 ```
41
42 ### Headers
43
44 ```bash
45 -A <str>         # --user-agent
46 -b name=val      # --cookie
47 -b FILE          # --cookie
48 -H "X-Foo: y"    # --header
49 --compressed     # use deflate/gzip
50 ```
51
52 ### SSL
53
54 ```bash
55     --cacert <file>
56     --capath <dir>
57 ```
58
59 ```bash
60 -E, --cert <cert>     # --cert: Client cert file
61     --cert-type       # der/pem/eng
62 -k, --insecure        # for self-signed certs
63 ```
64
65 ## Examples
66 {: .-one-column}
67
68 ```bash
69 # Post data:
70 curl -d password=x http://x.com/y
71 ```
72
73 ```bash
74 # Auth/data:
75 curl -u user:pass -d status="Hello" http://twitter.com/statuses/update.xml
76 ```
77
78 ```bash
79 # multipart file upload
80 curl -v -include --form key1=value1 --form upload=@localfilename URL
81 ```