curl cheat sheet
curl sends HTTP requests from the terminal. These are the options worth remembering.
Basic requests
curl <url>- GET and print the body
curl -i <url>- Include response headers
curl -I <url>- Headers only (HEAD request)
curl -L <url>- Follow redirects
curl -s <url>- Silent: no progress meter
curl -v <url>- Verbose: show connection and headers
Send data
curl -d "a=1&b=2" <url>- POST form data
curl -H "Content-Type: application/json" -d '{"a":1}' <url>- POST JSON
curl -X PUT -d '{"a":1}' <url>- Choose another method
curl -F "file=@photo.jpg" <url>- Upload a file as multipart form
curl --data-urlencode "q=rock & roll" <url>- Encode a value for you
Headers and auth
curl -H "Accept: application/json" <url>- Set a header
curl -H "Authorization: Bearer <token>" <url>- Bearer token
curl -u user:password <url>- Basic authentication
curl -A "my-agent/1.0" <url>- Set the User-Agent
curl -b "session=abc" <url>- Send a cookie
Files and output
curl -o file.html <url>- Save under a chosen name
curl -O <url>- Save under the remote file name
curl -C - -O <url>- Resume an interrupted download
curl -w "%{http_code}\n" -o /dev/null -s <url>- Print only the status code
Reliability
curl --max-time 10 <url>- Give up after 10 seconds
curl --retry 3 <url>- Retry on transient errors
curl -f <url>- Fail with an error on HTTP 4xx and 5xx
curl -k <url>- Skip certificate checks (testing only)
curl --resolve example.com:443:203.0.113.5 https://example.com- Force a host to an IP
Learn it properly