Learn how to show and send HTTP headers with cURL. Step-by-step guide with practical examples to display response headers, send custom headers, debug API requests, and test endpoints directly from the command line.
cURL is a powerful command-line tool used to transfer data with URLs. It supports multiple protocols including HTTP, HTTPS, FTP, and more. Developers often use cURL to test APIs, debug requests, and manage data transfers. In this guide, we’ll cover how to view HTTP headers and send custom headers with cURL.
Table of contents [Show]
To display only the response headers, use the -I
(or --head
) option:
curl -I https://example.com
This command sends a HEAD
request and shows headers like:
HTTP/2 200
date: Sat, 13 Sep 2025 08:00:00 GMT
content-type: text/html; charset=UTF-8
server: nginx
If you want both headers and the body, use the -i
option:
curl -i https://example.com
The output will include headers first, followed by the HTML body of the response.
To send custom headers, use the -H
(or --header
) option:
curl -H "Accept: application/json" https://api.example.com/data
You can pass multiple headers by repeating the -H
flag:
curl -H "Content-Type: application/json" \
-H "Authorization: Bearer your_token_here" \
https://api.example.com/data
When sending a POST request with headers:
curl -X POST https://api.example.com/login \
-H "Content-Type: application/json" \
-d '{"username":"user","password":"pass"}'
This example sends JSON data with custom headers to an API endpoint.
For debugging, use the -v
option to see detailed request and response headers:
curl -v https://example.com
It prints the full communication including request headers, making it useful for troubleshooting.
-I
→ Show only response headers-i
→ Show headers + body-H
→ Send custom headers-X
→ Specify request method (GET, POST, PUT, DELETE)-v
→ Verbose mode (request + response headers)Using cURL Post, you can easily send and view HTTP headers for debugging and API testing. Whether you need to check server response headers, send authentication tokens, or test custom requests, cURL provides a simple yet powerful way to handle HTTP communication directly from the command line.
Use the -I
option with cURL to show only response headers. Example:curl -I https://example.com
Use the -i
option with cURL to display both the headers and the response body. Example:curl -i https://example.com
You can send custom headers using the -H
flag. Example:curl -H "Accept: application/json" -H "Authorization: Bearer token" https://api.example.com
Use the -X POST
option with -H
to set headers and -d
to send data. Example:curl -X POST https://api.example.com/login -H "Content-Type: application/json" -d '{"username":"user","password":"pass"}'
Use the -v
option for verbose mode. It displays both request and response headers. Example:curl -v https://example.com
Your email address will not be published. Required fields are marked *