curl Verbose Mode and Debugging
Debug HTTP requests with curl verbose mode, trace output, and timing metrics. Inspect TLS handshakes, headers, and response details for troubleshooting.
Detailed Explanation
Debugging HTTP Requests with curl
curl is one of the best tools for debugging HTTP issues. Its verbose and trace modes reveal every detail of the request-response lifecycle, from DNS resolution to TLS negotiation.
Verbose Mode
The -v flag shows the full request and response conversation:
curl -v https://api.example.com/data
Output prefixes:
*— curl informational messages (DNS, TLS, connection)>— request headers sent to the server<— response headers received from the server
Trace Mode
For even more detail, --trace outputs a hex dump of all data:
curl --trace trace.log https://api.example.com/data
Or use --trace-ascii for a readable ASCII dump:
curl --trace-ascii - https://api.example.com/data
Timing Information
Use -w (write-out) to display timing metrics:
curl -s -o /dev/null -w "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nFirst byte: %{time_starttransfer}s\nTotal: %{time_total}s\n" \
https://api.example.com/data
Response Code Only
Check just the HTTP status code:
curl -s -o /dev/null -w "%{http_code}" https://api.example.com/health
Inspecting TLS Details
curl -v --tlsv1.2 https://example.com 2>&1 | grep "SSL\|TLS\|certificate"
Silent Mode with Errors
Use -sS to suppress progress output while still showing errors:
curl -sS https://api.example.com/data
Debugging Checklist
When an API request fails, use this systematic approach:
- Check connectivity:
curl -vto verify DNS and TCP connection - Inspect headers: Verify Content-Type, Authorization, and other required headers
- Check TLS: Look for certificate errors or version mismatches
- Examine timing: Use
-wto identify where latency occurs - Compare with working request: Diff the verbose output of working vs failing requests
Write-Out Variables
Key -w variables: %{http_code}, %{content_type}, %{size_download}, %{speed_download}, %{url_effective}, %{num_redirects}, %{ssl_verify_result}.
Use Case
A developer troubleshooting a failing API integration needs to inspect the full HTTP conversation including TLS handshake, request headers, and response timing.