curl: HTTP Debugging in CLI
cURL is the standard tool for debugging HTTP in the terminal. It ships out of the box on Linux and macOS and is present in most Docker images. Need to quickly check an API, inspect response headers, or trace a redirect issue — one command line is enough.
Basic Debug Flags
The most common scenario: get a response and see what the server returned. The -i flag prints headers before the body, -v enables verbose mode with connection details.
The difference: -i shows headers plus body, -v adds DNS resolution, TLS handshake, and debug info before the request.
A HEAD request checks resource availability and metadata without downloading the body:
HEAD does not guarantee the server supports ranges or caching — this depends on server configuration.
Methods and Request Body
By default, curl sends GET. For other methods, use the -X flag.
Request body is passed via -d. For JSON APIs, a typical pattern:
Multiline JSON is easier to read in a heredoc when the body is large:
To send form data or data from a file:
Custom Headers
The -H flag adds or overrides a header. You can use -H multiple times.
Overriding the Host header is useful when debugging virtual hosts or proxies:
To remove a default header, use -H "Accept:" — empty value after the colon.
Auth and Certificates
Basic HTTP auth via -u in user:password format:
For Bearer tokens, use a header:
-u sends credentials in plain text if TLS is not used. Always use HTTPS for production servers.
When working with self-signed certificates, the -k flag disables verification:
For known hosts and pinned certificates:
Timeouts and Saving Response
By default, curl waits indefinitely. For scripts and monitoring, set limits:
| Flag | Purpose |
|---|---|
--max-time N | total timeout in seconds |
--connect-timeout N | connection timeout |
Saving the response:
Redirect stdout to pipe the response body:
Redirects
Curl does not follow redirects by default. The -L flag enables automatic redirection:
To debug a redirect chain:
-L limits redirect depth (default 50). Infinite redirect loops are a common cause of curl hanging.
A flag combination for a full picture when debugging an API:
This command shows request and response headers, saves the body to a file, and enforces a 10-second timeout.