Skip to content

Send a curl OPTIONS Request and Read Its Headers

Use curl to ask a server which communication options it offers for a resource, inspect the answer in response headers, and reproduce a browser CORS preflight from the command line. The HTTP OPTIONS method is different from curl's own command-line options, which are flags such as -X and -i.

Send OPTIONS and show the response headers

Set the request method with uppercase -X (long form --request). Lowercase -x is a different curl option for a proxy, so case matters. A plain OPTIONS call may print nothing because many responses carry no body; that empty output is not by itself an error. Add -i ( --include ) to print response headers before any body, which is where the useful answer usually lives. Use -v ( --verbose ) when you also need connection, TLS, request-line and header detail for debugging. Do not substitute -I, which sends a HEAD request instead of OPTIONS. To write only headers, use -D with a filename, or -D - for standard output. Referenced protected modules: code0001, code0002, code0003, code0004, code0005, code0014, code0015.

What the response headers mean

OPTIONS asks what communication options a target resource supports, and the server normally answers in headers. Two headers answer different questions and should not be confused. Allow lists methods the resource supports; it is required in a 405 Method Not Allowed response but optional in a successful OPTIONS response, and its ordering can change between runs. Access-Control-Allow-Methods is CORS-specific and tells a browser which methods a cross-origin request may use; browsers do not use Allow for CORS permission. If Allow is absent, that alone does not mean no methods are supported.

Reproduce a CORS preflight

A plain OPTIONS call does not reproduce a browser preflight. Browsers preflight only certain cross-origin requests: a simple POST may not trigger one, while Content-Type: application/json does because it is not a CORS-safelisted content type, as does a non-safelisted custom header. To reproduce a preflight, send OPTIONS with Origin, Access-Control-Request-Method and, when needed, Access-Control-Request-Headers. Then check four things in the reply: a 2xx status, Access-Control-Allow-Origin permitting your origin, the requested method in Access-Control-Allow-Methods, and any requested header in Access-Control-Allow-Headers. A wildcard origin cannot authorize a credentialed request using cookies or HTTP auth; the server must return the specific origin. Avoid redirects for preflights, since browser behaviour around them is inconsistent and some browsers still reject them. Note that curl does not enforce browser CORS, so a correct-looking curl preflight does not prove the browser will allow the full request; the actual response is checked too. Referenced protected modules: code0006, code0007.

Flags you will reach for next

Common flags used with OPTIONS include -X/--request to set the method, -H/--header to add a request header, -i/--include to show response headers, -v/--verbose for debug detail, -L/--location to follow redirects, and -o/--output or -O/--remote-name to save output. Two cautions: -d/--data sends a body form-encoded by default and selects POST unless another method was already chosen, so it does not by itself mean JSON; and -L combined with -X reuses the forced method on every redirect, which can hide a redirect when testing. Inspect the original URL with -i before using -L. Referenced protected modules: code0008, code0009.

Copy, share and convert safely

In browser DevTools, right-click a request in the Network tab and choose Copy as cURL. For a preflight, copy the OPTIONS entry, not the following POST; if no OPTIONS entry appears, the request may not have needed a preflight or the browser reused a cached one. Before sharing or converting a command, remove authorization headers, cookies, API tokens, sensitive query parameters, and credentials or personal data in the body. Converted code still needs review and testing, and a browser fetch call remains subject to CORS. Referenced protected module: code0016 for the server-wide form below.

Server-wide OPTIONS and troubleshooting checklist

For a server-wide query, use --request-target '*' to send OPTIONS * instead of a URL path; --http1.1 gives the classic HTTP/1.1 form. This asks about the server in general and does not enumerate routes, and support varies by server. For troubleshooting: a blank terminal usually means an empty body, so add -i or -v; missing CORS headers after a realistic preflight may mean the server does not allow CORS for that origin or request; a 405 on the real request means the endpoint does not support that method regardless of CORS, even if a preflight advertised it; and curl exits successfully on HTTP 4xx or 5xx by default, so check the status or add --fail in scripts. Referenced protected modules: code0012, code0013, code0016.

From single tests to fetching at scale

Repeated page fetching at scale involves proxies, anti-bot systems and JavaScript rendering, which a scraping API can handle. The source workflow authenticates with an Authorization Bearer header using an owner-supplied key, uses GET typically, or POST and PUT for forms and stateful endpoints, and uses -G to send data values as query parameters. OPTIONS forwarding for CORS preflight testing is not documented in the source, so such a service cannot be assumed to proxy a preflight or test a site's OPTIONS response. Owner-confirmed details: API base URL {{OWNER_API_BASE_URL}}, credential variable {{OWNER_API_KEY_ENV_VAR}}, free-credit terms {{OWNER_FREE_CREDITS}}, and signup destination {{OWNER_SIGNUP_URL}}. Referenced protected module: code0011 for example response metadata headers.

curl flag map for OPTIONS testing
FlagUse with OPTIONS
-X, --requestSets the request method string.
-H, --headerAdds a request header, such as Origin.
-i, --includeIncludes response headers before the body.
-v, --verbosePrints protocol, connection and header debug detail.
-D, --dump-headerWrites only response headers to a file or standard output.
-L, --locationFollows redirects; inspect the original URL first with -i.
--request-target '*'Sends the server-wide OPTIONS * form.
--failMakes curl exit non-zero on HTTP errors in scripts.

Flags are curl command-line options, distinct from the HTTP OPTIONS method.

Frequently asked questions

Does a curl OPTIONS request count against my API's rate limits?

It may. Some servers route OPTIONS through the same rate-limiting layer as other methods, while CORS middleware may answer preflights before application-level limiting runs. Check the API documentation for its specific behaviour.

What are curl options?

They are command-line flags that alter how curl sends a request or handles its response. Most have long forms, for example -X is --request, -H is --header, and -d is --data. Use curl --help all or man curl for the full list. They are separate from the HTTP OPTIONS method, which curl can send as a request method.

Can browsers cache the result of a preflight OPTIONS request?

Yes. A server can return Access-Control-Max-Age in the preflight response so a browser caches the result for matching requests, subject to browser-specific limits. curl has no preflight cache; each command is a fresh HTTP request.

How do I see the response headers of an OPTIONS request?

Add -i to include response headers, or -v for verbose debugging output. To write only headers, use -D headers.txt, or -D - to send them to standard output.

Can curl send a server-wide OPTIONS * request?

Yes. Use --request-target '*' to send the asterisk form instead of a URL path. It works over HTTP/2; --http1.1 only gives the classic OPTIONS * HTTP/1.1 request. It asks about the server generally and does not list routes, and support varies by server.

# Send an OPTIONS request and include the response headers
curl -X OPTIONS https://httpbin.org/anything -i
curl -X OPTIONS https://httpbin.org/anything
# -v shows verbose protocol and connection information, including headers
curl -X OPTIONS https://httpbin.org/anything -v
# Reproduce a browser CORS preflight for a proposed cross-origin JSON POST
curl -i -X OPTIONS https://httpbin.org/anything \
  -H "Origin: https://example.com" \
  -H "Access-Control-Request-Method: POST" \
  -H "Access-Control-Request-Headers: content-type"
# -d sends a request body and uses POST here; no need for -X POST
curl https://httpbin.org/anything -d "name=value&foo=bar" -i
# Fetch a page through ScrapingBee and print only the response headers
curl -G "{{APP_BASE_URL}}/api/v1/" \
  -H "Authorization: Bearer $SCRAPINGBEE_API_KEY" \
  --data-urlencode "url=https://books.toscrape.com/" \
  -d "render_js=false" \
  -s -D - -o /dev/null
curl -s -i -X OPTIONS https://httpbin.org/get \
  -H "Origin: https://example.com" \
  -H "Access-Control-Request-Method: DELETE" | grep -iE "^HTTP|^allow|^access-control-allow-methods"

curl -s -i -X DELETE https://httpbin.org/get | grep -iE "^HTTP|^allow"
curl -s -X OPTIONS https://httpbin.org/anything -D - -o /dev/null
curl -i --http1.1 --request-target '*' -X OPTIONS https://curl.se/