🌐
curl cheat sheet
curl transfers data using URLs. Useful flags: -s silent, -S show errors even when silent, -L follow redirects, -f fail on HTTP errors.
Click any command to copy it.
Basic requests
| Command | What it does |
|---|---|
curl https://example.com | GET a URL and print the body. |
curl -I https://example.com | Fetch headers only. |
curl -i https://example.com | Include response headers with the body. |
curl -L https://example.com | Follow redirects. |
curl -o file.html https://example.com | Save to a named file. |
curl -O https://example.com/file.zip | Save using the remote file name. |
curl -C - -O https://example.com/big.iso | Resume an interrupted download. |
Sending data
| Command | What it does |
|---|---|
curl -X POST -d 'a=1&b=2' https://example.com/api | POST form data. |
curl -H 'Content-Type: application/json' -d '{"a":1}' https://example.com/api | POST JSON. |
curl -X PUT -d @data.json -H 'Content-Type: application/json' URL | Send a request body from a file. |
curl -F 'file=@photo.jpg' https://example.com/upload | Upload a file as multipart form data. |
curl --data-urlencode 'q=hello world' URL | URL-encode a form value. |
curl -X DELETE https://example.com/api/1 | Send a DELETE request. |
Authentication and headers
| Command | What it does |
|---|---|
curl -u user:password URL | HTTP basic authentication. |
curl -H 'Authorization: Bearer TOKEN' URL | Send a bearer token. |
curl -H 'Accept: application/json' URL | Set a custom header. |
curl -A 'my-agent/1.0' URL | Set the User-Agent. |
curl -b cookies.txt -c cookies.txt URL | Send and save cookies. |
Debugging and scripting
| Command | What it does |
|---|---|
curl -v URL | Verbose: show the request, response headers and TLS handshake. |
curl -s -o /dev/null -w '%{http_code}\n' URL | Print only the HTTP status code. |
curl -s -o /dev/null -w '%{time_total}\n' URL | Print the total request time. |
curl --max-time 10 --retry 3 URL | Give up after 10 seconds, retry up to 3 times. |
curl --resolve example.com:443:203.0.113.5 https://example.com | Test a server by IP while sending the right hostname. |
curl -k https://self-signed.example | Destructive: Skip certificate verification. Only for testing, never in production. |
curl --compressed URL | Request and decode a compressed response. |
curl -x http://proxy:3128 URL | Use an HTTP proxy. |
Frequently asked questions
How do I see only the status code?
Use curl -s -o /dev/null -w '%{http_code}' URL.
Why does curl print nothing for a redirect?
curl does not follow redirects by default. Add -L.