OSDN Git Service

Regular updates
[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: don't show progress meter or errors
21 -S           # --show-error: when used with --silent (-sS), show errors but no progress meter
22 ```
23
24 ```bash
25 -i           # --include: Include the HTTP-header in the output
26 -I           # --head: headers only
27 ```
28
29 ### Request
30
31 ```bash
32 -X POST          # --request
33 -L               # follow link if page redirects
34 -F                   # --form: HTTP POST data for multipart/form-data
35 ```
36
37 ### Data
38
39 ```bash
40 -d 'data'    # --data: HTTP post data, URL encoded (eg, status="Hello")
41 -d @file     # --data via file
42 -G           # --get: send -d data via get
43 ```
44
45 ### Headers
46
47 ```bash
48 -A <str>         # --user-agent
49 -b name=val      # --cookie
50 -b FILE          # --cookie
51 -H "X-Foo: y"    # --header
52 --compressed     # use deflate/gzip
53 ```
54
55 ### SSL
56
57 ```bash
58     --cacert <file>
59     --capath <dir>
60 ```
61
62 ```bash
63 -E, --cert <cert>     # --cert: Client cert file
64     --cert-type       # der/pem/eng
65 -k, --insecure        # for self-signed certs
66 ```
67
68 ## Examples
69 {: .-one-column}
70
71 ```bash
72 # Post data:
73 curl -d password=x http://x.com/y
74 ```
75
76 ```bash
77 # Auth/data:
78 curl -u user:pass -d status="Hello" http://twitter.com/statuses/update.xml
79 ```
80
81 ```bash
82 # multipart file upload
83 curl -v -include --form key1=value1 --form upload=@localfilename URL
84
85 # multipart form: send data from text field and upload file
86 curl -F person=anonymous -F secret=@file.txt http://example.com/submit.cgi
87 ```
88
89 ```bash
90 # Use Curl to Check if a remote resource is available
91 # details: https://matthewsetter.com/check-if-file-is-available-with-curl/
92 curl -o /dev/null --silent -Iw "%{http_code}" https://example.com/my.remote.tarball.gz
93 ```