cheat-sheets

curl

curl transfers data over HTTP(S), FTP and many other protocols. For TLS debugging also see OpenSSL.

Documentation: curl Docs

Common Options #

OPTIONDESCRIPTION
-sSilent (no progress bar)
-SShow errors even when silent (use as -sS)
-fFail on HTTP errors (exit non-zero for 4xx/5xx)
-LFollow redirects
-o <FILE> / -OSave to a file / save using the remote name
-IHeaders only (HEAD request)
-iInclude response headers in output
-vVerbose, shows the request and TLS handshake
-kSkip certificate verification (testing only)
-H "Name: value"Add a header
-X <METHOD>Set the HTTP method
-d <DATA>Send a POST body
-u <USER>:<PASS>Basic auth
-A "<UA>"User agent
-m <SEC>Max total time
--connect-timeout <SEC>Connection timeout
--retry <N>Retry on transient errors
-C -Resume a download
-w "<FORMAT>"Print info after the transfer
--resolve <HOST>:<PORT>:<IP>Override DNS for one request
-x <PROXY>Use a proxy

Reliable script default: curl -fsSL <URL>

Requests #

COMMANDDESCRIPTION
curl -fsSL <URL> -o <FILE>Download a file
curl -I <URL>Show response headers
curl -X POST -H "Content-Type: application/json" -d '{"a":1}' <URL>POST JSON
curl --json '{"a":1}' <URL>POST JSON (curl 7.82+, sets headers)
curl -d "a=1&b=2" <URL>POST form data
curl -F "file=@photo.jpg" <URL>Upload a file (multipart)
curl -T file.txt <URL>PUT a file
curl -X DELETE <URL>DELETE
curl -H "Authorization: Bearer <TOKEN>" <URL>Bearer token
curl -u <USER>:<PASS> <URL>Basic auth
curl --cookie-jar jar.txt <URL> / --cookie jar.txtSave / send cookies
curl --data-urlencode "q=hello world" <URL>URL-encode data
curl 'https://example.com/file[1-5].txt' -ODownload a range

Timing and Diagnostics #

COMMANDDESCRIPTION
curl -o /dev/null -sS -w "%{http_code}\n" <URL>Print only the status code
curl -o /dev/null -sS -w "dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n" <URL>Timing breakdown
curl -sS -o /dev/null -w "%{redirect_url}\n" <URL>Where a redirect goes
curl -v --http2 <URL> / --http1.1 / --http3Force an HTTP version
curl --tlsv1.2 --tls-max 1.2 <URL>Force TLS 1.2
curl --resolve example.com:443:203.0.113.10 https://example.comTest a server before changing DNS
curl --interface <IF> <URL>Use a specific network interface
curl -4 <URL> / -6Force IPv4 / IPv6
curl ifconfig.meYour public IP

With jq #

bash
curl -fsS https://api.github.com/repos/<OWNER>/<REPO>/releases/latest | jq -r .tag_name

See jq.

Config File #

~/.curlrc applies defaults, for example:

--fail
--location
--silent
--show-error

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.