Request Header and Response Header are both a part of the HTTP protocol, which is the standard used for communication between web browsers and web servers. The Request Header is sent by the browser as part of an HTTP request, and it contains information such as the type of request, the URL of the requested page, and any authentication credentials. The Response Header is sent by the server in response to the request, and it contains information such as the status code of the response, the content type of the page, and any authentication credentials.

Advertisement

Together, the Request and Response Headers help to ensure that data is sent securely and accurately between the browser and the server. Request and Response Headers are essential for web developers as they provide important information for debugging and troubleshooting. If you’re interested in learning more about Request and Response Headers, a good place to start is by reading up on the HTTP protocol.

cURL is a command line utility used to transmit data over 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

Use --versbose or -v option with the curl command to fetch the request header and response header values as following:

curl --verbose google.com 
cURL – get the request header and response header values

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

Wrap Up

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.

Share.

Leave A Reply