How to Show Response Headers with cURL

A drawing of a laptop displaying curl -I next to the title

Share

IN THIS ARTICLE:

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.

A drawing of a code box under the title

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:

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.

A drawing of curl showing a full HTTP header under the title

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.

a screenshot of a computer program under the title

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.
Various text boxes with code under the title

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
a computer screen with text overlay under the title

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
A drawing of an HTTP header under the title

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:

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.

About the author

Yazan is a Software Engineer at Proxidize with a passion for technology and a love for building things with code. He has worked in several industries, including consulting and healthcare, and is currently focused on proxy technologies.
IN THIS ARTICLE:

Save Up To 90% on Your Proxies

Discover the world’s first distributed proxy network, which guarantees the best IP quality, reliability and price.

Related articles

Free Proxies: 7 Reasons Why You Should Never Use Them

Have you ever been tempted to use a free proxy to access websites that are blocked in your country or

Abed Elezz

The Impact of Automation on Data Collection

Data collection is a fundamental aspect of market research, serving as the foundation for insights that drive strategic business decisions.

Zeid Abughazaleh

What is a Headless Browser?

If you have explored guides on web scraping, you have most likely come across the term headless browser. What does

Zeid Abughazaleh

How to Parse XML in Python

Learning to parse XML in Python is a good skill to have when working with structured data. XML is used

Zeid Abughazaleh

Start for Free! Start for Free! Start for Free! Start for Free! Start for Free! 

Talk to Our Sales Team​

Looking to get started with Proxidize? Our team is here to help.

“Proxidize has been instrumental in helping our business grow faster than ever over the last 12 months. In short, Proxidize has empowered us to have control over every part of our business, which should be the goal of any successful company.”

mobile-1.jpg
Makai Macdonald
Social Media Lead Specialist | Product London Design UK

What to Expect:

By submitting this form, you consent to receive marketing communications from Proxidize regarding our products, services, and events. Your information will be processed in accordance with our Privacy Policy. You may unsubscribe at any time.

Contact us
Contact Sales