HTTP troubleshooting curl Cheat Sheet banner

curl Cheat Sheet

Use curl to test websites, APIs, redirects, headers, status codes, SSL and response timing directly from the command line.

Start here

Quick checks

Fetch a page

curl https://example.com

Headers only

curl -I https://example.com

Silent output

curl -s https://example.com

Save to file

curl -o page.html https://example.com

Headers and user agents

Send custom header

curl -H "X-Test: 1" https://example.com

Change user agent

curl -A "Googlebot" https://example.com

Show request and response headers

curl -v https://example.com

Send Host header to an IP

curl -H "Host: example.com" http://192.0.2.10

Status codes and timing

Status code only

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

Timing summary

curl -s -o /dev/null -w "DNS:%{time_namelookup} Connect:%{time_connect} Total:%{time_total}\n" https://example.com

Download size

curl -s -o /dev/null -w "%{size_download}\n" https://example.com

Final URL

curl -Ls -o /dev/null -w "%{url_effective}\n" https://example.com

Redirects

TaskCommand
Show redirect responsecurl -I http://example.com
Follow redirectscurl -L http://example.com
Show redirect chaincurl -IL http://example.com
Limit redirectscurl -L --max-redirs 5 http://example.com

SSL and protocol checks

Verbose TLS details

curl -vI https://example.com

Ignore certificate errors

curl -k https://example.com

Use only for testing.

Force HTTP/1.1

curl --http1.1 -I https://example.com

Force HTTP/2

curl --http2 -I https://example.com

API examples

POST form data

curl -X POST -d "name=value" https://example.com/api

POST JSON

curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' https://example.com/api

Bearer token

curl -H "Authorization: Bearer TOKEN" https://example.com/api

Basic auth

curl -u username:password https://example.com/private

Website troubleshooting recipes

Check a site through a specific IP

curl --resolve example.com:443:192.0.2.10 https://example.com/

Check cache headers

curl -I https://example.com | grep -Ei "cache|age|etag|expires"

Check compression

curl -H "Accept-Encoding: gzip" -I https://example.com

Compare user agents

curl -A "Mozilla/5.0" -I https://example.com
curl -A "Googlebot" -I https://example.com
HTTP workflows

curl workflows for website checks

Headers only

curl -I https://example.com

Status code only

curl -o /dev/null -s -w "%{http_code}\n" https://example.com

Follow redirects

curl -IL https://example.com

Timing breakdown

curl -o /dev/null -s -w "connect:%{time_connect} start:%{time_starttransfer} total:%{time_total}\n" https://example.com
FAQ

Frequently Asked Questions

How do I show only HTTP headers with curl?

Use curl -I URL.

How do I follow redirects with curl?

Use curl -L, or curl -IL for redirect headers.

How do I show only the status code?

Use curl -o /dev/null -s -w "%{http_code}\n" URL.

How do I set a timeout?

Use --max-time SECONDS.