cURL Headers: How to Send, Customize, and Manage HTTP Headers
When working with HTTP, each client-server connection consists of HTTP requests and responses, both contained within HTTP headers, which store additional information about HTTP, authorization headers, and Accept headers. A curl header controls these aspects instead of browser settings.
Nowadays, web developers and QA engineers set curl commands in the command line interface to examine web servers and web applications, test APIs with more metadata, and troubleshoot difficult errors. Being able to set curl options and send precise headers for different use cases is essential for reliable debugging and automation.
Published:
28.11.2025
Reading time:
8 min
Read on to learn about setting up curl, using curl commands with header options, and making functional requests.
What Are cURL Headers?
HTTP headers are key-value pairs that pass with requests and responses. Headers contain names and values that provide information about an HTTP request, response, and data transport.
These headers include content types, authentication credentials, cache limitations, and data interpretation methods, with most clients giving appropriate defaults.
In curl, these are called ‘cURL headers,’ however they are generic headers used everywhere on the web in http protocols. Curl’s command line interface lets you examine, edit, and add headers. This functionality lets one set the json format for transferring json data, content types based on http operations, and more.
How to Send HTTP Headers With cURL
To send headers with curl, you typically use the -H or –header flag. The simplest curl header example looks like this:
curl -H "Header-Name: value" https://example.com
Here the h option (-H) tells curl to add one custom header and send it with your http requests. Whenever you need curl send header behavior for a quick test, you start by setting -H “Name: value” and then adjust the URL or other options as needed.
You can set curl to use different http methods with -X GET, -X POST, and so on, and still send the same header. For post requests, combine -H “Content-Type: application/json” with -d ‘{“key”:”value”}’ to send json data in the request body. This pattern works across many curl commands and options when you need to send precise headers.
Sending Custom and Multiple Headers

Sending Multiple Headers at Once
Adding custom multiple headers to requests with curl is simple. This is because you can add custom headers with -H options, including authentication, tracing, format suggestions, your custom API key correlation ID, and content type and acceptability settings.
Sending Empty Headers
You can also send empty headers with curl by writing something like -H “Header-Name:”. This is useful when sending custom requests where you want to override client defaults or clear values the server no longer needs. In some API specifics, you even pass an empty header value to disable certain behavior.
Removing a Header
Some servers and utilities treat an override and empty header as a header removal, not a browser’s default. Minimizing curl requests without necessary headers helps you send only those with server-relevant information.
Viewing and Retrieving Headers
Understanding what went out and what came back is as important as setting up a curl header when testing. There are several curl options, including -i, -I, -v, and –dump-header, that allow you to inspect the HTTP headers of incoming and outgoing requests alongside a standard response.
Show Response Headers (-i / -I flags)
To check http headers returned by the server, you can use -i or -I. The -i flag prints the response headers together with the response body, while -I makes a HEAD request and shows only headers. This lets you inspect information such as content types, json format, and accept headers. For example, you might set a curl accept header and then run –dump-header headers.txt so the output that follows is saved under a clear file name.
Verbose Mode (-v)
Verbose mode displays curl’s request and response headers and network connection details using the “-v” flag. This makes it simpler to decipher what curl is actually asking from the server and what is being received, which can be very helpful when diagnosing headers-related issues.
Saving Headers to a File
With –dump-header, curl can write response headers to a separate file while leaving the contents of the response body on stdout or in another file. This is handy when web debugging tools need a stable file name full of header metadata and additional information.
Common Use Cases
Private APIs, caching, and response kinds are common uses of curl with custom headers. A typical curl header may include authentication credentials and client information for web servers and web applications. With proper curl setup, curl with header can handle APIs with header requirements.
Sending Authenticated Requests
Many secured APIs need Token-based Authorization headers. When working with curl, you can use a curl authorization header with Authorization: Bearer TOKEN to authenticate and trust your custom headers.
Specifying Payload Encoding
For endpoints accepting JSON data, provide `Content-Type` as `application/json` for correct server parsing. Specifying `Accept` with `application/json` guarantees `json` format and data comply with accepted content types.
Changing Response Format
Certain APIs answer with XML, JSON, or other data formats, looking at the Accept HTTP header to identify the format. One argument can change the response format.
Conditional Requests and Referer
HTTP headers like “If-Modified-Since” and “Referer” add additional information about cache, navigation, and client details, making requests more efficient and giving the server enough information to respond.
Advanced Tips for Working With Headers
Most of the time, advanced header workflows in curl are about automation and reuse. When you set curl to load headers from files or combine them with additional flags, it makes mass testing a lot easier for web developers who are busy.
Use Header Files for Bulk Testing
Instead of duplicating the same custom headers with each request, web developers can fill custom headers to a text file and reference the same filename in several commands. Web developers can use a text file to fill authentication and JSON custom headers. With the right tools and a common custom header text file, web developers may conduct multiple similar requests in an API test with configurations that are in line with changing needs.
Combine Headers With Other Flags
When you use headers with other curl commands and options, they become even more powerful. You can send structured data by using -X POST, -H “Content-Type: application/json,” and -d ‘”key”:”value”‘ on the command line. Making more sophisticated requests that nevertheless function consistently throughout multiple tests is possible by including additional options like cookies or timeouts.
Troubleshooting Common cURL Header Issues
When working with any curl header you send, it’s easy to run into subtle problems: a typo in the name, a misplaced quote, or a header the server never expected. These issues can make requests fail silently, return unexpected responses, or trigger server-side restrictions that are hard to see at first glance.
Double-Check Header Syntax
Start by double-checking the basics. Check http headers you are setting: make sure names and values follow the Name: value pattern, quotes are paired correctly, and character escapes are valid. Even a missing space or stray quote can stop a header from being parsed at all.
Verify Header Support
Verify everyday information first. Inspect HTTP headers: To protect names and values, use `:` inside `Name: value`, balance quotes, and utilize legal escapes.
Even an omitted space character can cause HTTP header processing issues.
Case Sensitivity Problems
HTTP header names are defined as case-insensitive, but some tools, libraries, or back-end frameworks still expose them in a case-sensitive way. If something looks correct but fails, try matching the exact casing shown in the API or server examples.
Analyze Server Response
Finally, evaluate the wire level events. Use the options ‘v’, ‘i’, ‘I’, or ‘–dump-header’ to see what went out as ‘headers’ and ‘how’ the ‘server’ reacted, including ‘status lines’ and ‘response bodies’.
cURL Header Examples (Quick Reference)
Here are a few quick curl commands you can copy. Each example shows how to set curl to send specific http headers to web servers, so you can set curl with header flags in real API checks. To add header to curl, start with the -H option and adjust the value.
Simple example with one custom header.
curl -H "X-Demo: test" https://example.com
Example sending json data to an API.
curl -H "Content-Type: application/json" -d '{"name":"demo"}' https://api.example.com
Example of a token auth header.
curl -H "Authorization: Bearer TOKEN" https://api.example.com/secure
Example of sending multiple headers.
curl -H "X-Feature: on" -H "X-Trace: abc123" https://example.com
Example clearing a header value.
curl -H "X-Trace:" https://example.com
Conclusion
You’ve seen examples of curl setting options and building custom headers for testing and other real-world usage, resulting in improved http requests in any environment. You can use headers in many ways as a web developer and handle most instances with these features.
Always carry these examples to use a shortcut on new projects you develop or debug.
In This Article
Ready to get started?
Related posts


