Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Commands»cURL – How to display request headers and response headers

    cURL – How to display request headers and response headers

    By RahulDecember 12, 20223 Mins Read

    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 
    
    how to get request and response header with curl
    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.

    curl request header response header
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Uptime Command in Linux

    A Quick Reference Guide to Uptime Command in Linux

    fallocate Command in Linux (Allocate the Space for a File)

    fallocate Command in Linux (Allocate the Space for a File)

    Sed Command to Delete Lines in a File

    Sed Command to Delete Lines in a File

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.