As a developer when working with APIs, troubleshooting HTTP responses, or optimizing server performance, response headers can tell you a lot from content type and caching rules to redirect info and rate limits. While browsers hide most of this behind DevTools, cURL gives you full, direct access from the command line.
If you’ve ever wondered how to view HTTP headers using cURL, the good news is it’s just a matter of using the right flags. But which flags show headers only, which include the response body, and which let you debug both request and response?
In this article, we’ll break down the different ways to view response headers with cURL, how to save them, and when to use each approach whether you’re debugging an API call or just checking if a CDN is doing its job.

How to Get Headers Only with cURL
The simplest way to view HTTP response headers using cURL is by using the -I flag (also written as --head
). This tells cURL to send a HEAD
request, which asks the server to respond with headers only no body content.
Example:
curl -I https://example.com
This command will return output like:
HTTP/2 200
date: Tue, 02 Jul 2024 10:00:00 GMT
content-type: text/html; charset=UTF-8
server: nginx
cache-control: max-age=3600
The -I
flag is useful when you want to quickly check:
- If a server is live
- The HTTP status code (like 200, 301, 404)
- Redirects, CORS headers, caching, content types, and more
Since -I
uses a HEAD
request, it won’t return the actual page or response body, just the headers. Some servers may even behave differently for HEAD vs. GET requests (e.g., skipping auth or cookies), so this flag is ideal for quick inspections, not for simulating full browser behavior.

Show Headers With the Full Response
If you want to see both the headers and the response body in a single request for example, to check headers while also viewing the API response or HTML content you can use the -i
flag.
Example:
curl -i https://example.com
This sends a normal GET
request and includes the headers at the top of the response.
Sample Output:
HTTP/2 200
date: Tue, 02 Jul 2024 10:00:00 GMT
content-type: text/html; charset=UTF-8
server: nginx
<!doctype html>
<html>
<head>...</head>
<body>...</body>
</html>
When to use -i
:
- When you want to debug headers and content together
- When testing an API response or page output
- When comparing how headers change across environments (e.g.,staging vs production)
If you’re parsing the response in a script, -i
might break tools that expect raw JSON or HTML since the headers will be included at the top.

Show Only Headers from a GET Request (No Body)
Sometimes, you want to inspect the response headers from a real GET request, but you don’t care about the body (or don’t want it cluttering your terminal). This is especially useful when you’re checking redirect behavior, CORS policies, rate limits, or caching headers.
To do that, you can combine a few cURL flags:
Example:
curl -s -D - https://example.com -o /dev/null
What each flag does:
-D
: Dumps the response headers to standard output.-o: /dev/null
: Sends the response body to a black hole (which you can’t view).-s
: Runs in silent mode (you won’t see any progress bar or errors unless it’s critical).
Sample Output:
HTTP/2 200
date: Tue, 02 Jul 2024 10:00:00 GMT
content-type: application/json
cache-control: no-cache
When to use this:
- You want the full headers from a GET request (unlike -I, which sends a HEAD request)
- You’re scripting something and need a clean headers-only output
- You’re validating actual server responses, including cookies, redirect chains, and authentication-related headers.

Save Headers to a File (Using -D headers.txt
)
If you want to save response headers for later analysis or feed them into another tool or script cURL makes it easy with -D
flag.
Example:
curl -D headers.txt https://example.com -o /dev/null
What each flag does:
-D headers.txt
: Saves the headers to a file named headers.txt-o /dev/null
: Prevents the body from being saved or displayed
Optional: Add -s
to make the command silent. Refer to the example below:
curl -s -D headers.txt https://example.com -o /dev/null
Sample Output:
HTTP/2 200
date: Tue, 02 Jul 2024 10:00:00 GMT
content-type: application/json
x-powered-by:Express
When to use this:
- You’re debugging an API and want to inspect headers across multiple calls
- You want to compare headers from different servers (e.g.,staging vs production)
- You’re writing automation scripts and want to log HTTP metadata without parsing in real-time

Show Both Requests & Response Headers (Using -v
)
If you want to see all data, the headers your client sends and the headers the server responds with use the -v
(verbose) flag. This is especially useful when debugging authentication, redirects, cookies, or content negotiation.
Example:
curl -v https://example.com
What to expect from this command:
- Request headers (what cURL sends to the server)
- Response headers (what the server sends back)
- A breakdown of the SSL handshake
Sample Output:
* Trying 93.184.216.34:443...
* connected to example.com (93.184.216.34) port 443 (#0)
> GET / HTTP/2
> Host: example.com
> User-Agent: curl/8.0.1
> Accept: */*
< HTTP/2 200
< Date: Tue, 02 Jul 2024 10:00:00 GMT
< Content-Type: text/html; charset=UTF-8
< Server: nginx
When to use -v
:
- You want to confirm what headers your client is sending (e.g. Authorization , Accept , User-Agent)
- You’re troubleshooting auth issues or CORS problems
- You’re inspecting redirects or cookies being set

Common Use Cases for Viewing Headers with cURL
Viewing HTTP headers is just a powerful way to understand how servers, APIs, and content delivery behave. Below are some of the most common real-world use cases used by developers:
- Debugging API calls for quick check
- Checking redirects (you should inspect location headers to trace)
- Verifying caching behavior
- Troubleshooting CORS errors
- Inspecting cookies
- Analyzing CDN or proxy behavior
Conclusion
cURL is a great tool for inspecting HTTP traffic and viewing response headers is a key part of debugging, optimizing, and securing any web application.
Key Takeaways:
- Use curl
-I
to send a HEAD request and see headers only (no body). - Use curl
-i
to include headers with the response body. - Combine
-s -D - -o /dev/null
to get headers only from a GET request. - Use
-D headers.txt
to save headers to a file for later analysis. - Use
-v
to see both request and response headers ideal for debugging.
Whether you’re checking API status codes, debugging authentication flows, or optimizing caching behavior, knowing how to show headers (and when to use which flag) can save you time and headaches.