How to View HTTP Headers Using cURL and Other Command Line Tools


2 views

The simplest way to view HTTP headers is using cURL with the -I or -v flag:


# Get only response headers
curl -I https://www.example.com/test.php

# Verbose output showing both request and response headers
curl -v https://www.example.com/test.php

For more advanced header inspection:


# Using httpie (modern alternative to curl)
http -h HEAD https://www.example.com/test.php

# Using wget
wget --server-response --spider https://www.example.com/test.php

To extract specific headers using grep:


curl -sI https://www.example.com | grep -i 'content-type\|server'

For tracking redirect chains:


curl -IL https://www.example.com/test.php

To see exactly what headers your client is sending:


curl -v -o /dev/null https://www.example.com/test.php

Create a bash function for quick header checks:


headers() {
  curl -IL "$@" | grep -v "HTTP/[12].[01]"
}
# Usage: headers https://www.example.com



The most common and versatile way to check HTTP headers from the command line is using cURL:

curl -I https://www.example.com/test.php

The -I flag tells cURL to fetch headers only. For more detailed output including both headers and body, use:

curl -i https://www.example.com/test.php

For servers that don't support HEAD requests (which cURL -I uses), try these alternatives:

curl -v https://www.example.com/test.php > /dev/null

Or using wget:

wget --server-response --spider https://www.example.com/test.php

To see headers through all redirects:

curl -IL https://www.example.com/test.php

The -L flag follows redirects while -I maintains header-only output.

To extract just one header (e.g., Content-Type):

curl -sI https://www.example.com/test.php | grep -i content-type

For HTTP/2 headers, use the --http2 flag:

curl -I --http2 https://www.example.com/test.php

Here's a complete example showing common use cases:

#!/bin/bash # Check headers and follow redirects curl -IL https://www.example.com/test.php # Get just the status code curl -s -o /dev/null -w "%{http_code}" https://www.example.com/test.php # Check timing information curl -w "@curl-format.txt" -o /dev/null -s https://www.example.com/test.php