Skip to content

curl Show Response Headers: Flags, Output and Debugging

Response headers carry the server's side of the HTTP conversation: the status line, content type, caching rules, cookies, redirect targets and rate-limit hints. curl can expose that metadata in several ways, and the right flag depends on whether you want headers alone, headers plus body, a saved copy, or a full request trace. This guide maps each option to the debugging task it solves and explains how to read the fields you are most likely to need.

Which curl flag shows response headers?

The fastest check is a HEAD request. Use -I (capital i) when you only need the response headers and do not want the body. Use -i (lowercase i) when you want the headers printed above the body in the same output. Use -D when the headers should be written to a file or to stdout. Use -v when you need the full request/response trace, including connection and TLS details.

The practical decision is:

  • Headers only, no body: -I.
  • Headers and body together: -i.
  • Headers saved for later comparison or parsing: -D.
  • Full debug trace including what curl sent: -v.
  • Follow redirects and show the final headers: add -L.
  • Suppress the progress meter but keep errors visible: combine -s with -S.

On macOS and Linux, curl is usually available in the terminal. On Windows, recent PowerShell and Command Prompt versions include curl; if the command is not recognized, install it or update the environment. In PowerShell, wrap URLs containing & in quotes so the shell does not treat it as an operator.

Show only response headers with curl -I

curl -I https://httpbingo.org/html sends a HEAD request. The server replies with metadata but no body, which is ideal when you want to check status, content type, server software or caching rules without downloading the page.

A typical response begins with a status line such as HTTP/1.1 200 OK. Read that first:

  • 200 means the request succeeded.
  • 301 or 302 means a redirect; the location header says where the client should go next.
  • 401 or 403 usually means authentication is missing or access is restricted.

After the status line, content-type tells you whether the server returned HTML, JSON, XML or something else. server is optional but, when present, identifies the software that handled the request. Exact values vary by site and by the moment you run the command.

If the site redirects, -I alone shows the redirect response rather than the final destination. Add -L so curl follows the chain and prints the final headers: curl -I -L https://httpbingo.org/redirect/2.

Show headers and body together with curl -i

curl -i https://httpbingo.org/html prints the response headers first, then a blank line, then the body. That blank line is the separator between metadata and content; after it you will usually see HTML beginning with <!DOCTYPE html> or <html>.

This mode is useful when you need to confirm both what the server said and what it returned. If the output feels noisy because of the progress meter, add -s: curl -is https://httpbingo.org/html. Silent mode hides the progress meter, but it can also hide error messages, so pair it with -S when you still want failures reported.

Save response headers to a file with curl -D

-D (or --dump-header) writes the response headers to a file. This is handy when you want to compare two runs, share the headers with a teammate, or parse them later.

  • Save headers and still print the body: curl -D headers.txt https://httpbingo.org/html.
  • Save headers and discard the body: curl -D headers.txt -o /dev/null https://httpbingo.org/html.
  • On Windows, /dev/null does not exist; use NUL instead: curl -D headers.txt -o NUL https://httpbingo.org/html.
  • Print headers to the terminal without creating a file: curl -D - https://httpbingo.org/html. Here - means stdout.

Inspect JSON and XML API headers

When you debug an API, the headers often answer the first questions faster than the body does. They can show the returned format (content-type), whether the response is cacheable (cache-control), how many requests remain (X-RateLimit-*), and whether authentication or permissions failed.

For a JSON endpoint, run curl -i https://httpbingo.org/json. A content-type: application/json header means the body is JSON and should be parsed as such. Query parameters work the same way; include them in the URL, for example curl -i "https://httpbingo.org/get?limit=10".

For an XML endpoint, run curl -i https://httpbingo.org/xml. A content-type: application/xml header confirms that the response is XML. The flag mechanics do not change between formats; only the header value you are checking changes.

If you need a detailed view of everything curl sends and receives, use -v instead of -i.

Send request headers with curl -H

Inspecting response headers is only half of the conversation. Many APIs also expect request headers for authentication, content negotiation or rate limiting. The -H flag adds a header to the request.

  • Send a bearer token: curl -H "Authorization: Bearer YOUR_TOKEN" https://httpbingo.org/bearer.
  • Ask for JSON: curl -H "Accept: application/json" https://httpbingo.org/bearer.
  • Send several headers at once by repeating -H.
  • Let curl handle compressed responses with --compressed.

These options combine naturally with the inspection flags above: send the headers you need, then add -i or -v to see what came back.

Copy a browser request as a curl command

Modern sites send many headers, cookies and tokens that are tedious to rebuild by hand. Most browsers can generate the curl command for you from the Network tab. The generated command includes the URL, method, headers, cookies and sometimes the request body, so you can replay the exact request from a terminal.

Chrome and Firefox:

  1. Open the page and open Developer Tools (F12 or right-click, then Inspect).
  2. Go to the Network tab and reload the page so requests are captured.
  3. Find the request you want; the filter box or Fetch/XHR and Doc tabs help narrow the list.
  4. Right-click the request and choose Copy, then Copy as cURL.
  5. Paste the command into the terminal and add -i or -v to inspect the response headers.

Safari hides its developer tools by default. Enable them once under Safari, Settings, Advanced, then turn on Show features for web developers. Open Develop, then Show Web Inspector, go to the Network tab, reload, right-click the request and copy it as curl. Firefox-based browsers such as LibreWolf follow the same steps as Firefox.

Debug redirects, caching, cookies and authentication

Once headers are visible, they become a fast diagnostic layer. The table below maps common symptoms to the header to read and the curl flag that exposes it.

SymptomHeader to readcurl flagWhat it tells you
Page or API moves elsewherelocation with status 301 or 302-i, then add -LWhere the client is being sent next; -L follows the chain
Stale or unexpectedly cached contentcache-control, etag, expires-IHow long a response may be reused and whether a version identifier changed
Session or login behaviorset-cookie-i or -c cookies.txtWhich cookies the server wants the client to store
Missing or rejected credentialsstatus 401 or 403, plus auth-related headers-i with -HWhether a token is missing, expired or lacks permission
TLS or connection troubleverbose connection trace-vHandshake, certificate and protocol details

A redirect example: curl -i https://httpbingo.org/redirect/2 may return HTTP/1.1 302 Found with location: /relative-redirect/1. The location header tells the client where to go next. Add -L to follow the chain automatically, or combine -v -L to see every request and response along the way.

A caching example: curl -I https://httpbingo.org/cache/3600 may return cache-control: public, max-age=3600. Here max-age=3600 means the response may be cached for one hour. An etag is a version identifier for a resource; when the content changes, the tag changes, which lets clients check whether they need to download it again.

A cookie example: curl -i "https://httpbingo.org/cookies/set?cookie1=v1&cookie2=v2" may show set-cookie lines. To store cookies for later requests, use curl -c cookies.txt with the same URL; the jar file can be reused in subsequent calls.

An authentication example: a request without a token may return HTTP/1.1 401 Unauthorized. Send the token with curl -i -H "Authorization: Bearer secret_token" https://httpbingo.org/bearer. If it still fails, read the response headers first; they often hint at missing permissions, expired tokens or an incorrect request format.

For TLS or connection problems, curl -v https://httpbingo.org/html shows the connection process, the TLS handshake and all request and response headers. That trace helps identify certificate problems, protocol mismatches or unexpected redirects.

Turn a working curl command into reusable code

A common workflow is to get the request right in curl first, then move it into an application. The command already contains the endpoint, headers and authentication method, so it is a reliable specification for the code you write next.

  1. Test and debug the request with curl.
  2. Confirm that the headers and response look correct.
  3. Convert the working command into your target language.
  4. Drop the generated snippet into a script or application.

A converter can save time when the command contains many headers, cookies or tokens, because it keeps those details intact instead of asking you to retype them. The same command can become a request in Python, JavaScript, Go or another language.

Where curl header checks help in practice

Developers reach for curl headers when they need to know why an API request failed, whether a site is redirecting traffic, which cookies or auth headers are required, how caching affects responses, or what content type a server returns. The same skill matters when working with scraping infrastructure, because many sites respond differently depending on the headers they receive; a request that looks suspicious or incomplete may be blocked or served different content. Understanding headers makes it easier to diagnose that behavior before changing a scraper.

Header debugging map
SymptomHeader to readcurl flagWhat it tells you
Page or API moves elsewherelocation with status 301 or 302-i, then add -LWhere the client is being sent next; -L follows the chain
Stale or unexpectedly cached contentcache-control, etag, expires-IHow long a response may be reused and whether a version identifier changed
Session or login behaviorset-cookie-i or -c cookies.txtWhich cookies the server wants the client to store
Missing or rejected credentialsstatus 401 or 403, plus auth-related headers-i with -HWhether a token is missing, expired or lacks permission
TLS or connection troubleverbose connection trace-vHandshake, certificate and protocol details

Header names and status codes are standard HTTP terms; the example values in the guide come from public httpbingo.org test endpoints and may differ when you run the commands.

Frequently asked questions

How can I copy a curl request with headers from Chrome?

Open Chrome DevTools, go to the Network tab, reload the page, then right-click the request you want and choose Copy, then Copy as cURL. This copies the full request, including headers, so you can replay it in your terminal.

How do I see headers when calling an XML API with curl?

Add -i to print headers alongside the body, or -I to request headers without the body, on the XML endpoint URL. The output lets you check the returned Content-Type value, such as application/xml, along with any charset parameter, so you can confirm the API actually served XML rather than an error page or a different format.

How do I copy a curl command with headers from Safari?

Enable the Develop menu in Safari settings, open Web Inspector, and go to the Network tab. Reload the page, right-click a request, and copy it as a curl command. You can then run it in your terminal to inspect the headers.

Where can I practice using curl headers on real web scraping projects?

A practical approach is to test requests against real websites and APIs while inspecting their headers with curl. That helps you understand authentication, cookies and browser-like requests. You can build and test these workflows using a web scraping API.

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
date: Wed, 04 Mar 2026 16:28:49 GMT
content-length: 421
server: Fly/eb4db471f (2026-03-03)

{
  "slideshow": {
    "author": "Yours Truly",
    "date": "date of publication",
    "slides": [
      // ...
    ]
  }
}