In a similar vein to my previous post I want to have a place where I keep track of all the useful curl switches.
-
-L
follow redirects-s
silent-v
verbose-o
output file
12# download a file silently and save to the name specified; follow any redirectscurl -sL "https://something/latest?version=3&os=linux" -o something.linux.tar.gz-H
(or--header
) send custom headers
1curl -H "Accept: text/html" http://something-d
(or--data
) send data (inline, or a file specified by@<filename>
)
1234567# Send data inlinecurl -H "Content-Type: application/json" \-d "{\"value\":\"node JS\"}" http://something# Send data in a file insteadcurl -H "Content-Type: application/json" \-d @file.json http://something--data-binary
same as above for binary files-X "METHOD"
to make a request of custom method
1234curl localhost:2019/load \-X POST \-H "Content-Type: application/json" \-d @caddy.json
-k
skip any SSL checks (useful for self-signed certs)
Request types:
-
- By default curl does a
GET
request. -d
or-F
makes it aPOST
request.-I
generates aHEAD
(use this to view headers only)-T
sends aPUT
-X "METHOD"
for a custom method (which could beGET
orPOST
etc.)
1curl -X GET -H 'X-NSONE-Key: $API_KEY' https://api.nsone.net/v1/zones
View Response Headers:
1curl -s -D - -o /dev/null http://example.com-s
: Avoid showing progress bar-D -
: Dump headers to a file, but-
sends it to stdout-o /dev/null
: Ignore response body
This is better than
-I
as it doesn’t send aHEAD
request, which can produce different results. - By default curl does a
It’s better than -v
because you don’t need so many hacks to un-verbose it. Thanks SO.
Finding where a Url redirects to:
1 |
curl -Ls -o /dev/null -w '%{url_effective}\n\n' https://mysite.com |
-L
follow redirects-s
silent-o
output file (to/dev/null
in this case as we don’t care for the output)-w
what to output after completion (in this caseurl_effective
followed by two new lines as I like to space things out)
Thanks again, SO.