1 min read

cURL: Response Headers Only For Non GET Request

To inspect response headers using cURL, utilize the following commands:

For a GET request:

curl -I https://example.com

Unfortunately, this approach is limited to GET requests. For POST or other methods, employ the following command:

curl -X POST -sSD - https://example.com -o /dev/null

Refer to the manual for additional details:

-D, --dump-header <filename> Write the received headers to <filename>
-S, --show-error  Show error even when -s is used
-s, --silent      Silent mode

Please note the significance of the - before the URL, indicating that the output redirects to stdout.

Here is an illustrative example:

$ curl -X POST -sSD - https://httpbin.org/anything -o /dev/null
HTTP/2 200
date: Fri, 26 Jan 2024 03:27:28 GMT
content-type: application/json
content-length: 342
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true

Reference: https://stackoverflow.com/a/10060342/302974