How to Send HTTP Headers With cURL: A Beginner's Guide

HTTP headers contain most of the context that will inform a server who you are, what you want, and how to respond. Using cURL you'll be able to add, read, and troubleshoot those headers to ensure that your scraping or API calls are reliable. This guide will show you how to work with headers in cURL, how to send and view them, its use cases, and how you can solve common header issues.

Valentin Ghita

Technical Writer, Marketing, Research

Mihalcea Romeo

Co-Founder, CTO

updated 2026-04-14T16:10:45.555Z

Short overview of HTTP headers and cURL

HTTP headers are tiny lines of metadata that travel with every request and response. They tell a server who you are, what formats you accept, how you authenticate, whether something is cached, and much more. cURL is a small but powerful command line tool that lets you set those headers precisely. If you build or debug APIs, test integrations, or route traffic through a proxy, cURL plus the right headers is the fastest way to reproduce and fix issues.

Which headers does cURL send by default

By default, cURL composes several headers for you. You will usually see:

  • User-Agent: curl/<version> so servers know the client type.
  • Accept: */* which means “I can accept any content type.”
  • Host: <hostname> derived from the URL you call.
  • Content-Length and Content-Type when there is a request body.
  • Expect: 100-continue may appear for larger uploads to avoid sending the whole body before the server is ready.

You rarely need to set these manually. It is better to override only what you actually need.

To see exactly what a server received from you while you experiment, point a request at a header echo endpoint in your examples. For instance:

How to add HTTP headers with cURL

You add headers with -H or --header. Each header uses the Name: value shape. Repeat the flag to include more than one.

The core -H "Name: value" pattern

On macOS or Linux, single quotes are handy when values contain shell characters:

On Windows, use curl.exe and double quotes to avoid PowerShell alias quirks:

Adding your own custom headers

Custom headers carry correlation IDs, feature flags, and other context your app understands. Here is a simple pattern you will reuse a lot:

The response will reflect your headers, which makes it easy to confirm spelling, casing, and values.

Advanced header tricks in cURL

Use verbose output to inspect headers

Verbose mode prints the full exchange. Lines that start with > are what you sent. Lines that start with < are what the server returned.

Adding -o /dev/null keeps the terminal focused on headers rather than the body.

Attach multiple headers in one request

Repeat -H to include several headers. cURL preserves the order.

Suppress or remove default headers

You can explicitly clear headers that cURL would send. This is useful for tests that must mimic very specific clients.

Those examples send the header name with an empty value, which servers typically treat as “not provided.”

Send an empty-value header

Sometimes an empty value is meaningful to the upstream service. You can include a header key with nothing after the colon:

Save headers to a file

Dump response headers to a file for later comparison or to attach to a bug report.

Display server response headers

There are two quick switches you will reach for most often:

Real-world uses for custom headers in cURL

Send authentication tokens and credentials

Bearer tokens belong in the Authorization header. Avoid hardcoding secrets in scripts.

If the service supports Basic auth, let cURL build the header correctly:

Request a specific response format

APIs often negotiate format with Accept. For writes, also set Content-Type.

Control the Referer header

Some endpoints use the Referer for analytics or allow lists. You can set or remove it explicitly.

# Set a specific Referer curl -H "Referer: https://www.anonymous-proxies.net/" http://httpbin.org/headers # Remove it entirely curl -H "Referer:" http://httpbin.org/headers

Set a custom User-Agent

Giving your requests a clear identity helps with observability and filtering. Choose something descriptive and stable.

This makes your traffic easy to spot in logs and aligns with good ecosystem etiquette.

Make conditional requests with cache headers

Conditional headers save bandwidth and speed up clients. If you have an ETag or last modified time, ask the server to respond only if content changed.

A real API may return 304 Not Modified when the condition matches. That tells you to reuse the cached representation.

Fixing common cURL header problems

Inspect responses for error details

Start by looking at the status code and any diagnostic headers the server includes. Use -i to show headers above the body or combine -v with -o /dev/null to focus on the exchange. Many APIs echo a request ID in a header. If you see one, include it in your support ticket so the backend team can find your exact call.

Check your header syntax

Every header must be Name: value. Do not add spaces before the colon. Quote values that contain spaces, commas, or shell-sensitive characters. On Windows, prefer curl.exe so you get the real cURL and not a shell alias. If a header is not appearing in the echo output, the most common culprits are a missing colon, a mismatched quote, or the shell consuming characters.

Confirm the server supports the header

Some headers are hints, not commands. For example, a server might ignore Range or Accept-Encoding depending on configuration. A simple method is to first verify that your request carries the header by calling the echo endpoint in your code examples, then try the real service and compare behaviors. If you see no change, the server likely does not honor that header for the resource you are testing.

Mind potential case sensitivity pitfalls

HTTP header names are case insensitive by the standard. X-Request-ID and x-request-id are equivalent on the wire. Values are not universally case insensitive. Tokens like Bearer in the Authorization header are often written with a specific capitalization in docs. Follow the API examples exactly, including punctuation like quotes around ETags. One more gotcha is historical spelling. The correct header is Referer, not Referrer.

Conclusion

As you’ve learned above, you should now know the basics: what headers are, how cURL applies its defaults, and how to add, view, and troubleshoot them.

Also, when you are ready to scale or target specific regions, you should learn how route traffic through our residential proxies, and here's exactly the only cURL with proxy guide you need. If you need help tuning headers or configuring cURL through our proxies, don't hesitate to contact our support team and they will help you with any problems you've got.

Recommended product

Buy Backconnect Proxies

Rotating IPs on every request. Scale scraping and automation without manual IP management.

Similar posts to this one

Read about the latest news and updates.

Curl with Python hero image
updated·2026-04-14T15:58:47.347Z

How to Use cURL With Python: A Complete Guide

cURL is best known as a command-line tool for handling web transfers, but you can also use its core functionality inside Python. That matters when you want more control over requests, headers, redirects, proxies, and response handling than simpler tools usually give you. In Python, PycURL brings that lower-level cURL behavior into your code, which makes it useful for testing APIs, automating requests, and scraping pages. In this guide, you’ll see how to use cURL with Python to send different types of requests, work with proxies, and scrape website data with PycURL.

Curl ignore ssl hero image
updated·2026-04-03T04:28:03.672Z

How to Ignore SSL Certificate Errors in cURL: Complete Guide

SSL certificates, more accurately TLS certificates, are what help browsers and tools like cURL confirm a website is genuine. They do this by checking the certificate comes from a trusted authority, matches the domain you requested and is still valid. When any of those checks fail, you will often see a warning or a blocked request because the client cannot reliably verify who it is talking to. Now, that does not always mean the site is unsafe, sometimes the certificate simply expired or the chain is misconfigured. In this guide, you will learn what are these SSL certificates, their common errors, and why you might want to bypass them with cURL.

Show http headers using curl hero image
updated·2026-04-14T16:07:49.019Z

How to Show HTTP Response Headers with cURL?

If you want to really understand how a website or API behaves, looking at the HTTP response headers is one of the easiest wins. With curl, you can see status codes, cookies, caching rules, redirects, security headers and more, all from your terminal. In this guide, you will learn how to show HTTP response headers with curl, understand common problems, and quickly debug your requests.

Curl Post Requests Hero Image.
updated·2026-04-03T04:28:04.670Z

How to Send cURL POST Requests: Step-by-Step Guide

At some point, if you're working with APIs, you will need to push data from the terminal. This is where cURL is great. In this tutorial, you will learn what a POST request is, how to send one with cURL, and the options that are useful for typical tasks.

 

Ready to get started?

We accept all forms of payment, including crypto.