Tools › Cheat sheets › Networking & Security › curl
🌐

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

CommandWhat it does
curl https://example.comGET a URL and print the body.
curl -I https://example.comFetch headers only.
curl -i https://example.comInclude response headers with the body.
curl -L https://example.comFollow redirects.
curl -o file.html https://example.comSave to a named file.
curl -O https://example.com/file.zipSave using the remote file name.
curl -C - -O https://example.com/big.isoResume an interrupted download.

Sending data

CommandWhat it does
curl -X POST -d 'a=1&b=2' https://example.com/apiPOST form data.
curl -H 'Content-Type: application/json' -d '{"a":1}' https://example.com/apiPOST JSON.
curl -X PUT -d @data.json -H 'Content-Type: application/json' URLSend a request body from a file.
curl -F 'file=@photo.jpg' https://example.com/uploadUpload a file as multipart form data.
curl --data-urlencode 'q=hello world' URLURL-encode a form value.
curl -X DELETE https://example.com/api/1Send a DELETE request.

Authentication and headers

CommandWhat it does
curl -u user:password URLHTTP basic authentication.
curl -H 'Authorization: Bearer TOKEN' URLSend a bearer token.
curl -H 'Accept: application/json' URLSet a custom header.
curl -A 'my-agent/1.0' URLSet the User-Agent.
curl -b cookies.txt -c cookies.txt URLSend and save cookies.

Debugging and scripting

CommandWhat it does
curl -v URLVerbose: show the request, response headers and TLS handshake.
curl -s -o /dev/null -w '%{http_code}\n' URLPrint only the HTTP status code.
curl -s -o /dev/null -w '%{time_total}\n' URLPrint the total request time.
curl --max-time 10 --retry 3 URLGive up after 10 seconds, retry up to 3 times.
curl --resolve example.com:443:203.0.113.5 https://example.comTest a server by IP while sending the right hostname.
curl -k https://self-signed.exampleDestructive: Skip certificate verification. Only for testing, never in production.
curl --compressed URLRequest and decode a compressed response.
curl -x http://proxy:3128 URLUse 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.

More Networking & Security cheat sheets

🔑 SSH🛰️ Linux networking🛡️ ufw🔐 OpenSSL🔒 Certbot (Let's Encrypt)🌐 Subnet / CIDR🧱 iptablesAll Networking & Security cheat sheets →
Copied to clipboard