OSDN Git Service

7606842b5b14946ad046617a4c380d20a05305c9
[twpd/master.git] / curl.md
1 ---
2 title: Curl
3 category: CLI
4 layout: 2017/sheet
5 updated: 2020-03-09
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           # --include: Include the HTTP-header in the output
25 -I           # --head: headers only
26 ```
27
28 ### Request
29
30 ```bash
31 -X POST          # --request
32 -L               # follow link if page redirects 
33 ```
34
35 ### Data
36
37 ```bash
38 -d 'data'    # --data: HTTP post data, URL encoded (eg, status="Hello")
39 -d @file     # --data via file
40 -G           # --get: send -d data via get
41 ```
42
43 ### Headers
44
45 ```bash
46 -A <str>         # --user-agent
47 -b name=val      # --cookie
48 -b FILE          # --cookie
49 -H "X-Foo: y"    # --header
50 --compressed     # use deflate/gzip
51 ```
52
53 ### SSL
54
55 ```bash
56     --cacert <file>
57     --capath <dir>
58 ```
59
60 ```bash
61 -E, --cert <cert>     # --cert: Client cert file
62     --cert-type       # der/pem/eng
63 -k, --insecure        # for self-signed certs
64 ```
65
66 ## Examples
67 {: .-one-column}
68
69 ```bash
70 # Post data:
71 curl -d password=x http://x.com/y
72 ```
73
74 ```bash
75 # Auth/data:
76 curl -u user:pass -d status="Hello" http://twitter.com/statuses/update.xml
77 ```
78
79 ```bash
80 # multipart file upload
81 curl -v -include --form key1=value1 --form upload=@localfilename URL
82 ```
83
84 ```bash
85 # Use Curl to Check if a remote resource is available
86 # details: https://matthewsetter.com/check-if-file-is-available-with-curl/
87 curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gz
88 ```