Main Tutorials

cURL – Display request headers and response headers

We can use curl -v or curl -verbose to display the request headers and response headers in the cURL command.

In the cURL response

  • The > lines are request headers.
  • The < lines are response headers.

1. curl -v http://google.com

Try curl -v to the Google search engine.

curl -v

Terminal

 curl -v http://google.com

* Rebuilt URL to: http://google.com/
*   Trying 172.217.166.142...
* TCP_NODELAY set
* Connected to google.com (172.217.166.142) port 80 (#0)
> GET / HTTP/1.1
> Host: google.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Date: Wed, 26 May 2021 00:00:02 GMT
< Expires: Fri, 25 Jun 2021 00:00:02 GMT
< Cache-Control: public, max-age=2592000
< Server: gws
< Content-Length: 219
< X-XSS-Protection: 0
< X-Frame-Options: SAMEORIGIN
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
* Connection #0 to host google.com left intact

2. Display only response headers in cURL

We can use curl --head to display only the response header in the cURL command.

Terminal

 curl --head http://google.com

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Wed, 26 May 2021 00:06:50 GMT
Expires: Fri, 25 Jun 2021 00:06:50 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN

3. References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Christoph
9 months ago

It should be noted that –head is doing a HEAD request, which sometimes returns a different response (e.g. 405 method not allowed) than doing a GET and printing the headers

vinay
1 year ago

Hi do you know how can we get a perticular response header tag using verbose

solicit
2 years ago

The -o switch should be added and preferably dump the HTML content to /dev/null

Loc
2 years ago

Thank you so much, Mr. Mkyong.