cURL is the ubiquitous command-line tool and library for transferring data using URL syntax across HTTP, HTTPS, FTP, and dozens of other protocols.
Basic HTTP Requests
# Standard GET request
curl https://example.com
# Follow HTTP 3xx redirects (-L / --location)
curl -L https://example.com
# Save response to a file matching remote filename (-O)
curl -O https://example.com/archive.zip
# Save response to a custom local file (-o)
curl -o local_file.html https://example.com
# Download with resumed transfer (-C -)
curl -C - -O https://example.com/largefile.iso
Request Inspection & Output Controls
| Flag | Name | Purpose |
|---|---|---|
-i, --include |
Include headers | Prints HTTP response headers along with body |
-I, --head |
Head only | Fetches HTTP headers only (HEAD request) |
-v, --verbose |
Verbose output | Displays full TLS handshake, request, and response |
-s, --silent |
Silent mode | Suppresses progress meter and error messages |
-S, --show-error |
Show error | When used with -s, prints errors if transfer fails |
Sending Data (POST, PUT, JSON)
# Form-encoded POST data (-d / --data)
curl -d "username=admin&password=secret" https://example.com/login
# Send JSON payload with Content-Type header
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "role": "developer"}'
# Read JSON payload directly from file
curl -X POST https://api.example.com/items \
-H "Content-Type: application/json" \
-d @data.json
# PUT request with explicit method (-X)
curl -X PUT https://api.example.com/items/42 -d "status=active"
Multipart File Uploads (-F)
# Upload a file as multipart/form-data
curl -F "file=@/path/to/photo.jpg" https://example.com/upload
# Upload file with custom MIME type and additional form fields
curl -F "[email protected];type=application/pdf" \
-F "category=finance" \
https://example.com/api/upload
Authentication & Headers
# Basic HTTP Authentication (-u username:password)
curl -u "myuser:mypassword" https://api.example.com/protected
# Bearer Token Authentication
curl -H "Authorization: Bearer <access_token>" https://api.example.com/me
# Custom User-Agent
curl -A "CustomBot/1.0" https://example.com
Cookies & SSL Controls
# Save cookies to cookie jar (-c) and send cookies from file (-b)
curl -c cookies.txt -d "user=me&pass=123" https://example.com/login
curl -b cookies.txt https://example.com/dashboard
# Ignore SSL certificate errors (self-signed certs)
curl -k https://localhost:8443
# Provide client certificate
curl --cert client.pem --key client.key https://secure.example.com
Useful Status Codes & Benchmarks
Check HTTP status code directly to stdout:
curl -s -o /dev/null -w "%{http_code}\n" https://example.com
Measure request latency metrics:
curl -s -o /dev/null -w "DNS: %{time_namelookup}s | Connect: %{time_connect}s | TTFB: %{time_starttransfer}s | Total: %{time_total}s\n" https://example.com