In a similar vein to my previous post I want to have a place where I keep track of all the useful curl switches.
-
-Lfollow redirects-ssilent-vverbose-ooutput 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-binarysame 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
-kskip any SSL checks (useful for self-signed certs)
Request types:
-
- By default curl does a
GETrequest. -dor-Fmakes it aPOSTrequest.-Igenerates aHEAD(use this to view headers only)-Tsends aPUT-X "METHOD"for a custom method (which could beGETorPOSTetc.)
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
-Ias it doesn’t send aHEADrequest, 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 |
-Lfollow redirects-ssilent-ooutput file (to/dev/nullin this case as we don’t care for the output)-wwhat to output after completion (in this caseurl_effectivefollowed by two new lines as I like to space things out)
Thanks again, SO.
