curl Cheat Sheet

Transfer data over HTTP(S) and more — headers, timeouts, auth, multipart uploads, and getting just the parts you need.

Networking4 sections · 29 commands
⌘K

Basic Requests

8
curl URL

GET and dump the body

curl -o FILE URL

Save output to a file

curl -o /dev/null -w '%{http_code}\n' URL

Just the status code

curl -L URL

Follow redirects

curl -I URL

HEAD request, headers only

curl --max-time 10 URL

Abort after 10 seconds

curl --connect-timeout 5 URL

Timeout for connecting

curl --retry 3 --retry-all-errors URL

Retry transient failures

POST, PUT & JSON

6
curl -X POST -d 'key=value' URL

URL-encoded form POST

curl -X POST -H 'Content-Type: application/json' -d '{"k":"v"}' URL

JSON POST

curl -X PUT -d @file.json URL

PUT from a file

curl -X DELETE URL

DELETE request

curl -X POST -F 'file=@local.png' -F 'note=hi' URL

Multipart upload

curl -X PATCH -d '{"k":"v"}' URL

PATCH with body

Auth & Headers

7
curl -H 'Authorization: Bearer TOKEN' URL

Bearer token header

curl -u USER:PASS URL

HTTP basic auth

curl -b 'Cookie: session=abc' URL

Send a cookie

curl -c cookies.txt URL

Save cookies to a jar

curl -b cookies.txt URL

Load cookies from a jar

curl --cert cert.pem --key key.pem URL

Mutual TLS (mTLS)

curl -u USER -H 'X-Pretty-Print: 1' https://api.github.com/repos/org/repo

Headers + basic auth combo

Debugging

8
curl -v URL

Verbose request/response trace

curl -sv URL 2>&1 | grep '^\*'

Only the TLS/handshake lines

curl --resolve example.com:443:127.0.0.1 URL

Override DNS for testing

curl -k URL

Skip TLS certificate checks (test only)

curl --http2 URL

Force HTTP/2

curl -x http://PROXY:PORT URL

Route through a proxy

curl -w 'dns:%{time_namelookup} tcp:%{time_connect} tls:%{time_appconnect} total:%{time_total}\n' -o /dev/null -s URL

Per-phase timing breakdown

curl -s URL | jq .

Pretty-print JSON output