Code & computing / QUICK REFERENCE

curl request essentials

Inspect HTTP responses, save files and send deliberate requests with explicit timeout and security behavior.

24 entries

Inspect responses

GET a page
curl https://example.com

Writes the response body to stdout. [1]

HEAD request
curl -I https://example.com

Requests headers; this is a HEAD method, not a GET without a body. [1]

Headers plus body
curl -i https://example.com

Includes response headers in output. [1]

Verbose connection details
curl -v https://example.com

Diagnostic output can expose headers and credentials. [1]

Follow redirects
curl -L https://example.com

Follows Location responses; confirm redirected destinations. [1]

Write headers separately
curl -D headers.txt -o body.html https://example.com

Writes or replaces two local files. [1]

Print status code
curl -sS -o /dev/null -w '%{http_code}\n' https://example.com

A 404 does not make plain curl fail by default. [1]

Fail on HTTP errors
curl --fail-with-body https://example.com

Nonzero exit for HTTP errors while retaining the body on supported curl versions. [1]

Build requests explicitly

Request JSON
curl -H 'Accept: application/json' https://example.com

Accept describes the desired response format. [2][1]

Custom header
curl -H 'X-Request-Label: atlas' https://example.com

Headers are sent to the remote endpoint. [2][1]

Encode GET parameters
curl -G --data-urlencode 'q=hello world' https://example.com

Appends an encoded query parameter. [2][1]

POST form data
curl --data-urlencode 'name=Atlas' https://example.com

Sends form data; this may change remote state. [2][1]

POST JSON
curl --json '{"name":"Atlas"}' https://example.com

Adds JSON headers and a request body on supported versions. [2][1]

Send JSON from a file
curl --json @request.json https://example.com

Reads the file as the request body. [2][1]

Send binary body unchanged
curl --data-binary @payload.bin https://example.com

Preserves bytes; choose Content-Type explicitly when needed. [2][1]

Use a trusted config file
curl --config request.conf

Configuration can send credentials; inspect its contents first. [2][1]

Bound requests and save output

Connection timeout
curl --connect-timeout 5 https://example.com

Bounds connection establishment, not the whole transfer. [3][1]

Whole-operation timeout
curl --max-time 20 https://example.com

Bounds the overall operation duration. [3][1]

Retry selected failures
curl --retry 3 https://example.com

Review retry safety before sending non-idempotent requests. [3][1]

Bound retry period
curl --retry 3 --retry-max-time 30 https://example.com

Stops starting retries after the configured period. [3][1]

Quiet but show errors
curl -sS https://example.com

Removes the progress meter, not error reporting. [3][1]

Choose output filename
curl -o page.html https://example.com

Creates or overwrites the specified file. [3][1]

Restrict allowed protocols
curl --proto '=https' --proto-redir '=https' -L https://example.com

Restricts initial and redirected transfer protocols. [3][1]

Installed capabilities
curl --version

Lists supported protocols, TLS backend and features. [3][1]

Reserved placement, separate from reference controls. No ad network is active.

Updated curl · modern command-line options

Sources

  1. curl command manual ↗
  2. HTTP with curl ↗
  3. Timeouts ↗