curl Cheat Sheet

The everyday curl set: requests, headers, output, auth, TLS, throttling, and timing breakdowns.

Basics

curl https://example.com            # simple GET, print body to stdout
curl -s https://example.com         # silent: hide progress meter and errors
curl -sS https://example.com        # silent, but still show errors
curl -v https://example.com         # verbose: show request + response headers, TLS handshake
curl -X POST https://example.com    # use a specific HTTP method (GET/PUT/DELETE/...)
curl --http2 https://example.com    # force HTTP/2 (if server supports it)

Output

curl -o out.html https://example.com      # save body to out.html
curl -O https://example.com/file.zip      # save using the remote file name
curl -D - https://example.com             # dump response headers to stdout (- = stdout)
curl -i https://example.com               # include response headers + body
curl -I https://example.com               # HEAD request: headers only, no body
curl --compressed https://example.com     # ask for gzip/deflate/br, auto-decompress

Redirects & retries

curl -L https://short.url/abc           # follow redirects (3xx) automatically
curl -L --max-redirs 5 https://...      # follow redirects, cap at 5 hops
curl --retry 3 https://example.com      # retry up to 3 times on transient errors
curl --retry 3 --retry-delay 2 ...      # wait 2s between retries
curl -f https://example.com             # fail loudly on HTTP 4xx/5xx (exit code 22)

Headers

curl -H "Authorization: Bearer TOKEN" https://api.example.com   # custom header
curl -H "Accept: application/json" https://api.example.com      # ask for JSON
curl -A "MyBot/1.0" https://example.com                         # set User-Agent
curl -e "https://example.com" https://example.com/page          # set Referer header

POST data

curl -d "a=1&b=2" https://example.com/form              # POST form data (url-encoded)
curl -d @data.json https://example.com/api             # POST body read from a file
curl --data-urlencode "q=hello world" https://...       # URL-encode the value for you
curl -X POST https://api.example.com/items \
  -H "Content-Type: application/json" \
  -d '{"name":"Widget","price":9.99}'                   # POST a JSON body
curl -F "file=@report.pdf" https://example.com/upload   # multipart upload: a file
curl -F "file=@a.png" -F "note=hi" https://...          # multipart: file + text field

Auth

curl -u user:pass https://example.com            # HTTP Basic auth
curl -u user https://example.com                 # prompt for the password interactively
curl -H "Authorization: Bearer TOKEN" https://api.example.com   # token / API key in header

Cookies

curl -b "session=abc123" https://example.com     # send a cookie string
curl -b cookies.txt https://example.com          # read cookies from a file (Netscape format)
curl -c cookies.txt https://example.com/login    # save response cookies to a file

TLS (certificates)

curl -k https://self-signed.badssl.com          # SKIP cert verification — testing only, never for real traffic
curl --cacert ./ca.pem https://internal.corp    # trust a custom CA certificate file

Transfer control

curl --limit-rate 200K https://example.com/big.zip    # cap download speed (K/M/G suffixes)
curl --max-time 30 https://example.com                # abort if the whole op takes > 30s
curl --connect-timeout 5 https://example.com          # abort if connect takes > 5s
curl -C - -O https://example.com/big.zip              # resume an interrupted download

Timing (find the slow part)

curl -o /dev/null -s -w "%{time_total}s\n" https://example.com
      # total time only; -o /dev/null discards the body
curl -o /dev/null -s -w "dns:%{time_namelookup} tcp:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n" https://example.com
      # full phase breakdown (values are cumulative seconds)
curl -o /dev/null -s -w "@timing.txt" https://example.com
      # read the -w format from a file (@- reads from stdin)
curl -o /dev/null -s -w "%{http_code} %{size_download} %{speed_download}\n" https://example.com
      # status code, bytes downloaded, average speed

Proxy

curl -x http://127.0.0.1:7890 https://example.com    # route through a proxy
curl -U user:pass -x http://proxy:8080 https://...   # proxy with authentication