env.dev

curl Cheat Sheet — HTTP Requests, File Transfers & API Testing from the Command Line

Quick reference for curl: GET/POST requests, headers, cookies, authentication, file uploads and downloads, debugging, TLS, proxies, and scripting patterns.

Last updated:

curl is a command-line tool for transferring data with URLs. It supports HTTP, HTTPS, FTP, and dozens of other protocols. This cheat sheet covers the most essential curl commands and flags for making HTTP requests, sending data, handling authentication, uploading files, debugging connections, and scripting — organized by workflow for fast lookup.

Basic Requests

CommandDescription
curl https://example.comFetch a URL and print response body to stdout
curl -o file.html https://example.comSave response to a file
curl -O https://example.com/report.pdfSave with the remote filename
curl -L https://example.comFollow redirects (3xx responses)
curl -s https://example.comSilent mode — suppress progress meter
curl -sS https://example.comSilent but still show errors
curl -f https://example.comFail silently on HTTP errors (no output on 4xx/5xx)
curl -I https://example.comFetch only the response headers (HEAD request)
curl -i https://example.comInclude response headers in the output

How Do You Send POST Requests with curl?

CommandDescription
curl -X POST https://api.example.com/itemsSend an empty POST request
curl -d "key=value&name=test" https://api.example.com/formPOST form-urlencoded data
curl -H "Content-Type: application/json" -d '{"name":"test"}' https://api.example.com/itemsPOST JSON data with explicit Content-Type header
curl --json '{"name":"test"}' https://api.example.com/itemsPOST JSON (curl 7.82+) — sets Content-Type and Accept headers automatically
curl -d @data.json https://api.example.com/itemsPOST data from a file
curl -X PUT -d '{"name":"updated"}' https://api.example.com/items/1Send a PUT request with data
curl -X PATCH -d '{"name":"patched"}' https://api.example.com/items/1Send a PATCH request
curl -X DELETE https://api.example.com/items/1Send a DELETE request

Headers and Cookies

CommandDescription
curl -H "Authorization: Bearer TOKEN" https://api.example.comSend a custom header
curl -H "X-Custom: value" -H "Accept: text/plain" URLSend multiple custom headers
curl -A "MyApp/1.0" https://example.comSet the User-Agent string
curl -e https://referrer.com https://example.comSet the Referer header
curl -b "session=abc123" https://example.comSend a cookie
curl -b cookies.txt https://example.comSend cookies from a file (Netscape format)
curl -c cookies.txt https://example.comSave response cookies to a file
curl -b cookies.txt -c cookies.txt https://example.comRead and write cookies (maintain session)

Authentication

CommandDescription
curl -u user:pass https://example.comHTTP Basic authentication
curl -u user https://example.comBasic auth — curl prompts for password interactively
curl -H "Authorization: Bearer TOKEN" https://api.example.comBearer token authentication
curl --negotiate -u : https://example.comKerberos/SPNEGO authentication
curl --digest -u user:pass https://example.comHTTP Digest authentication
curl -n https://example.comUse credentials from ~/.netrc file
curl --oauth2-bearer TOKEN https://api.example.comOAuth 2.0 bearer token (curl 7.83+)

How Do You Upload Files with curl?

CommandDescription
curl -F "file=@photo.jpg" https://api.example.com/uploadUpload a file as multipart/form-data
curl -F "file=@photo.jpg;type=image/jpeg" URLUpload with explicit MIME type
curl -F "file=@doc.pdf" -F "name=report" URLUpload file with additional form fields
curl -T file.txt https://example.com/upload/Upload via PUT (WebDAV, FTP, etc.)
curl -T "{file1,file2}.txt" ftp://ftp.example.com/Upload multiple files via FTP
curl --data-binary @image.png -H "Content-Type: image/png" URLUpload raw binary data in POST body

How Do You Download Files with curl?

CommandDescription
curl -o output.zip https://example.com/file.zipDownload and save with a custom filename
curl -O https://example.com/file.zipDownload and save with the remote filename
curl -O -C - https://example.com/file.zipResume an interrupted download
curl -O https://example.com/file[1-10].txtDownload a range of files using globbing
curl --limit-rate 1M -O https://example.com/large.isoLimit download speed to 1 MB/s
curl -Z -O https://a.com/1.zip -O https://b.com/2.zipDownload multiple files in parallel (curl 7.66+)
curl -J -O https://example.com/downloadUse filename from Content-Disposition header

Debugging and Verbose Output

CommandDescription
curl -v https://example.comVerbose output — shows request/response headers and TLS handshake
curl --trace trace.log https://example.comFull hex + ASCII trace of all data to a file
curl --trace-ascii trace.log https://example.comASCII-only trace (more readable)
curl -w "%{http_code}" -o /dev/null -s URLPrint only the HTTP status code
curl -w "%{time_total}\n" -o /dev/null -s URLMeasure total request time in seconds
curl -w "dns:%{time_namelookup} connect:%{time_connect} ttfb:%{time_starttransfer} total:%{time_total}\n" -o /dev/null -s URLDetailed timing breakdown
curl -D headers.txt https://example.comDump response headers to a file
curl --compressed https://example.comRequest compressed response (gzip, deflate, br) and decompress

TLS and Certificates

CommandDescription
curl -k https://self-signed.example.comSkip TLS certificate verification (insecure)
curl --cacert ca.pem https://example.comUse a custom CA certificate bundle
curl --cert client.pem --key client-key.pem URLClient certificate authentication (mTLS)
curl --tlsv1.3 https://example.comForce TLS 1.3
curl --tls-max 1.2 https://example.comSet maximum TLS version to 1.2
curl --pinnedpubkey "sha256//hash=" https://example.comPin a specific public key hash

Proxies and Network Options

CommandDescription
curl -x http://proxy:8080 https://example.comRoute request through an HTTP proxy
curl -x socks5://proxy:1080 https://example.comUse a SOCKS5 proxy
curl --noproxy "*.local,localhost" URLBypass proxy for specific hosts
curl --resolve example.com:443:1.2.3.4 https://example.comOverride DNS resolution for a host
curl --connect-timeout 5 https://example.comSet connection timeout to 5 seconds
curl -m 30 https://example.comSet maximum total time to 30 seconds
curl --retry 3 https://example.comRetry up to 3 times on transient errors
curl --retry 3 --retry-delay 2 https://example.comRetry with a 2-second delay between attempts
curl -4 https://example.comForce IPv4
curl -6 https://example.comForce IPv6

Frequently Asked Questions

What is the difference between -d and -F in curl?

The -d flag sends data as application/x-www-form-urlencoded (like an HTML form submission), while -F sends data as multipart/form-data (used for file uploads). Use -d for simple key-value data and API calls, and -F when you need to upload files.

How do you send JSON with curl?

Use curl --json '{"key":"value"}' URL (curl 7.82+), which automatically sets Content-Type: application/json and Accept: application/json. For older versions, use curl -H "Content-Type: application/json" -d '{"key":"value"}' URL.

How do you check the HTTP status code with curl?

Run curl -o /dev/null -s -w "%{http_code}" URL. The -o /dev/null discards the body, -s suppresses the progress bar, and -w "%{http_code}" prints the status code. Add \n for a trailing newline.

How do you follow redirects in curl?

Add the -L (or --location) flag: curl -L https://example.com. By default curl does not follow redirects. Use --max-redirs N to limit the number of redirects followed (default is 50 with -L).

How do you resume a failed download with curl?

Use curl -C - -O URL. The -C - flag tells curl to automatically detect the byte offset from the partially downloaded file and resume from where it left off.

What does curl -k do and when should you use it?

The -k (--insecure) flag tells curl to skip TLS certificate verification. Use it only for development or testing against self-signed certificates. Never use -k in production scripts — it disables protection against man-in-the-middle attacks.