The request headers contain the information about the resource that is required to be fetched. The response headers contain information about the response sent by the server. It’s something like server details and other information.
cURL is a command line utility used to transmit data over the different-2 protocols. It is a quick tool for developers to view the request header and response header values of a website.
1. cURL – Get Request Headers
-v option with the curl command to fetch the request header and response header values as following:
curl --verbose google.com
2. cURL – Get Response Headers
You can also use curl to fetch the response header values only. Use
-I option to get the response header values.
curl -I google.com
Output:HTTP/1.1 301 Moved Permanently Location: http://www.google.com/ Content-Type: text/html; charset=UTF-8 Date: Sat, 10 Sep 2022 09:25:56 GMT Expires: Mon, 10 Oct 2022 09:25:56 GMT Cache-Control: public, max-age=2592000 Server: gws Content-Length: 219 X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN
3. cURL – Get Custom Header Values
Sometimes you may need to fetch the specific header value. That is helpful for scripting and many other tasks. Use the grep command to filter specific values from complete header values. The
-F is used to search fixed string and
-i is used for case sensitive search.
curl -I google.com | grep -Fi "Content-Type"
Output:Content-Type: text/html; charset=UTF-8
cURL is a command line utility that is helpful for multiple tasks. We can also use curl to request a server for the details. This tutorial helped you to get the request header and response header values using the curl command line.