cURL Debugging, Performance, and Scripting

Tracing, DNS overrides, proxies, protocol selection, config files, timeouts, and script-friendly curl patterns.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Debugging and Diagnostics
Limit connect time
curl --connect-timeout 5 https://example.com

# Fail if the connection cannot be established quickly.

Limit total transfer time
curl --max-time 20 https://example.com

# Abort the request after a fixed total duration.

Override DNS resolution
curl --resolve example.com:443:127.0.0.1 https://example.com

# Map a hostname and port to a specific IP address.

Redirect one host:port to another
curl --connect-to example.com:443:staging.example.net:8443 https://example.com

# Change where curl connects without changing the URL's host name.

Use an HTTP proxy
curl -x http://proxy.example.com:8080 https://example.com

# Send requests through an HTTP proxy.

Use a SOCKS5 proxy
curl --socks5 localhost:1080 https://example.com

# Route a request through a SOCKS5 proxy.

Force HTTP/2
curl --http2 https://example.com

# Ask curl to use HTTP/2 where supported.

Try HTTP/3
curl --http3 https://example.com

# Attempt an HTTP/3 transfer when curl build and server support it.

Force IPv4
curl -4 https://example.com

# Resolve and connect using IPv4 only.

Force IPv6
curl -6 https://example.com

# Resolve and connect using IPv6 only.

## Config Files and Scripting
Use a curl config file
curl -K request.curl

# Load options from a config file.

Example curl config file
url = 'https://api.example.com/v1/items'
header = 'Accept: application/json'
header = 'Authorization: Bearer TOKEN'
silent
show-error

# Store headers, auth, and URL in a reusable config file.

Use --json shortcut
curl --json '{"name":"demo"}' https://api.example.com/v1/items

# Send JSON body with curl's JSON convenience option.

Use output variables
curl -o '#1-#2.txt' 'https://example.com/{dev,prod}/{a,b}'

# Name outputs using transfer variables.

Script-safe status check
status=$(curl -s -o /tmp/resp.json -w '%{http_code}' https://api.example.com/health)
[ "$status" -eq 200 ] && echo ok || echo fail

# Capture HTTP status for shell scripts.

Parse JSON with jq
curl -s https://api.github.com/repos/curl/curl | jq '.stargazers_count'

# Pipe JSON output to jq for filtering.

Send request body from a file
curl -X POST -H 'Content-Type: application/json' --data @payload.json https://api.example.com/items

# Post the contents of a local file as the request body.

Bypass proxy for specific hosts
curl --noproxy localhost,127.0.0.1 https://localhost:8443

# Skip proxy use for selected domains or hosts.

Recommended next

No recommendations yet.