55| Official Page | < https://curl.se/ > |
66| Source | < https://github.com/curl/curl > |
77| Download | < https://github.com/curl/curl/releases > |
8+ | Docker | < https://hub.docker.com/r/curlimages/curl > |
89| Docs | < https://everything.curl.dev > or < https://curl.se/docs/manpage.html > |
910| Book | < https://curl.se/docs/ > |
1011| Windows | ` scoop install curl ` |
1112| Ubuntu | ` sudo apt -y install curl ` |
1213
13- ## Random Examples
14+ ## Downloading Files
1415
15- Example to check /24 range in "abuseipdb.com" for the last 3 days
16+ Simple download
1617
17- ``` sh
18- curl -s -G https://api.abuseipdb. com/api/v2/check-block --data-urlencode " network=123.123.123.1/24 " -d maxAgeInDays= $DAYS -H " Key: apikeyfromabuseipdb.com " -H " Accept: application/json " | jq ' .data.reportedAddress '
18+ ``` sh
19+ curl -O https://example. com/file.zip
1920```
2021
21- If you want to inspect the headers of a response from some endpoint include the ` -I ` flag and ` curl ` will
22- return just the headers.
22+ Download with output filename
2323
24- ``` sh
25- curl -I localhost:3000/posts
24+ ``` sh
25+ curl -o myfile.zip https://example.com/file.zip
2626```
2727
28- Example of using curl with basic auth credentials
28+ Use -L to follow redirects:
2929
30- ``` sh
31- curl -u username:password staging. example.com
30+ ``` sh
31+ curl -L https:// example.com
3232```
3333
34- Query a website e.g. request a json response from cloudflare-dns.com on TXT records of the domain 0xfab1.net
34+ ## Authentication
35+
36+ Example of using curl with basic auth credentials
3537
3638``` sh
37- curl -s -H ' accept: application/dns-json ' ' https://cloudflare-dns.com/dns-query?name=0xfab1.net&type=TXT '
39+ curl -u username:password staging.example.com
3840```
3941
4042## Send Mail
4143
44+ Please note: Gmail no longer supports "less secure apps." Use [ App Passwords] ( https://support.google.com/accounts/answer/185833 ) instead.
45+
4246``` sh
43- curl --ssl-reqd --url ' smtps://smtp.gmail.com:465' --user ' username@gmail.com:password' --mail-from ' username@gmail.com' --mail-rcpt ' john@example.com' --upload-file mail.txt
47+ curl --ssl-reqd --url ' smtps://smtp.gmail.com:465' \
48+ --user ' username@gmail.com:app_password' \
49+ --mail-from ' username@gmail.com' \
50+ --mail-rcpt ' john@example.com' \
51+ --upload-file mail.txt
4452```
4553
4654mail.txt file contents:
@@ -55,28 +63,122 @@ I’m sending this mail with curl thru my gmail account.
5563Bye!
5664```
5765
58- Some more information:
66+ Use [ --netrc-file] ( https://everything.curl.dev/usingcurl/netrc ) instead of credentials in curl command for better security.
67+
68+ Example:
69+
70+ ``` sh
71+ curl --netrc-file ~ /.netrc staging.example.com
72+ ```
5973
60- - [ gmail: turn on access for less secure apps] ( https://myaccount.google.com/lesssecureapps )
61- - Use [ --netrc-file] ( https://everything.curl.dev/usingcurl/netrc ) instead of credentials in curl command
62- - [ Use curl with ssl] ( https://curl.se/docs/sslcerts.html )
74+ ``` txt
75+ machine staging.example.com
76+ login username
77+ password password
78+ ```
6379
6480## WebDAV
6581
66- Create Folders
82+ Create directories on WebDAV:
6783
6884``` sh
6985curl -X MKCOL ' http://your.server/uploads/nested_folder1' --user ' name:pwd'
7086```
7187
72- Copy Files
88+ Upload a file via WebDAV:
7389
7490``` sh
75- curl -T < filename > -u < username> : < password> < url > -o /dev/stdout
91+ curl -T file.txt ' http://your.server/uploads/file.txt ' --user ' username: password'
7692```
7793
78- Copy all files in a Folder (and subfolder). Folders must already exist.
94+ Upload all files in folder (directories must exist):
7995
8096``` sh
81- cd local_folder_to_upload && find . -exec curl -T {} ' http://your.server/uploads/{}' --user ' name:pwd ' \;
97+ cd local_folder_to_upload && find . -type f - exec curl -T {} ' http://your.server/uploads/{}' --user ' username:password ' \;
8298```
99+
100+ ## Random Examples
101+
102+ ### check netowrk range
103+
104+ Example to check /24 range in "abuseipdb.com" for the last 3 days
105+
106+ ``` sh
107+ DAYS=3
108+ curl -s -G " https://api.abuseipdb.com/api/v2/check-block" \
109+ --data-urlencode " network=123.123.123.1/24" \
110+ -d " maxAgeInDays=$DAYS " \
111+ -H " Key: apikeyfromabuseipdb.com" \
112+ -H " Accept: application/json" \
113+ | jq ' .data.reportedAddress'
114+ ```
115+
116+ If you dont have jq installed:
117+
118+ - ubuntu: ``` sudo apt install jq ```
119+ - windows: ``` scoop install jq ```
120+
121+ ### Inspect headers
122+
123+ If you want to inspect the headers of a response from some endpoint include the ` -I ` flag and ` curl ` will return just the headers.
124+
125+ ``` sh
126+ curl -I localhost:3000/posts
127+ ```
128+
129+ or a verbose setting:
130+
131+ ``` sh
132+ curl -v localhost:3000/posts
133+ ```
134+
135+ ### Request JSON
136+
137+ Query a website e.g. request a json response from cloudflare-dns.com on TXT records of the domain 0xfab1.net
138+
139+ ``` sh
140+ curl -s -H ' accept: application/dns-json' ' https://cloudflare-dns.com/dns-query?name=0xfab1.net&type=TXT'
141+ ```
142+
143+ ### Send JSON
144+
145+ This command sends a POST request with JSON data.
146+
147+ ``` sh
148+ curl -X POST https://api.example.com/posts \
149+ -H ' Content-Type: application/json' \
150+ -d ' {"title":"Hello","body":"Curl"}'
151+ ```
152+
153+ ### Timing
154+
155+ This command measures the performance of a request.
156+
157+ It shows:
158+
159+ - DNS lookup time (time_namelookup)
160+ - TCP connection time (time_connect)
161+ - total request duration (time_total)
162+
163+ The response body is ignored (-o /dev/null).
164+
165+ ``` sh
166+ curl -w " @-" -o /dev/null -s " https://example.com" << 'EOF '
167+ time_namelookup: %{time_namelookup}\n
168+ time_connect: %{time_connect}\n
169+ time_total: %{time_total}\n
170+ EOF
171+ ```
172+
173+ ### Using a proxy
174+
175+ Route the request through a proxy server (http://proxyserver:port ).
176+ This is useful for debugging, bypassing restrictions, or accessing internal networks.
177+
178+ ``` sh
179+ curl -x http://proxyserver:port https://example.com
180+ ```
181+
182+ ### More
183+
184+ - [ Use curl with ssl] ( https://curl.se/docs/sslcerts.html )
0 commit comments