cURL is the command utility in Linux that is used to share data from or to the servers using different protocols, including HTTPS and FTP. At the same time, the HTTPS headers are the type of HTTPS requests that pass some other information or the metadata of the request.
The cURL command uses different protocols in Linux. Still, this article will focus on the cURL command with the HTTPS headers and the blog contents:
- Prerequisite: Install cURL on Linux
- What are the HTTPS Headers
- Display the Raw Message
- Display the Header
- Pass Custom Headers
- Add Multiple Headers
- Pass Empty Header
- Print the Server Response
Let’s start with the article by exploring the HTTP headers!
Prerequisite: Install cURL on Linux
To manage the HTTPS with the cURL command, the cURL command should be installed on the computer. For this, use the following commands:
|Debian/Ubuntu-based||sudo apt install curl|
|CentOS/RHEL-based||sudo yum install curl|
|ArchManjaro-based||sudo pacman -S curl|
What are the HTTPS Headers?
As already discussed, HTTPS headers pass additional information along, allowing communication between the client and the server.
The header has the following parts:
- Case sensitive name
- Colon (:)
The general syntax of the HTTPS headers is:
Header-Name: Value "accept": "*/*", "host": "echo.hoppscotch.io", "user-agent": "-o", "x-country": "US",
Now we will learn to use the cURL command in Linux to display the HTTPS Headers.
How to Display the Raw Message Using the cURL?
The cURL displays the raw message in Linux by connecting to the specified URL. For example, we will display the information of itslinuxfoss with the “-v” option. The v option is used to display the progress of the execution of the command:
$ curl -v https://itslinuxfoss.com
In the above output, we can see that all the information is being displayed of the connection between two servers, including the HTTPS Headers.
The verbose option is useful, especially when troubleshooting the configuration in the servers.
How to Display the Header Only Using the cURL?
Instead of displaying all the information about the connection with the other servers, we can only display the headers. To do so, we have to use the “–head” option with the cURL command:
$ curl --head https://itslinuxfoss.com
Only the Headers are displayed on the connection with the itslinuxfoss using the cURL command.
How to Pass Custom Headers Using the cURL?
Sometimes you must pass the custom headers with the request for the HTTPS. This is possible with the “-H” option of the cURL command. The general syntax for passing the custom headers is:
$ curl -H 'Header: Value' http://example.com
To understand the above general syntax of cURL, we will pass the “Accepted-Language” header with the value of “en-US” to the itslinuxfoss URL:
$ curl -H 'Accepted-Language: en-US' https://itslinuxfoss.com
How to Add Multiple Headers Using the cURL?
Similar to the above-explained usage of passing the headers, you can also pass multiple custom headers. To do so, you will use the “-H” option of the cURL command with every header which is supposed to pass. For example, with the “Accepted Language” header, we will also pass the header “x-country” with the value “US” using the command:
$ curl -H 'Accepted-Language: en-US' -H 'x-country: US' https://itslinuxfoss.com
How to Pass Empty Header Using the cURL?
You can also pass the empty header, a header having no value, using the cURL command. For example, we will pass the header “City” with an empty value using the command:
$ curl -H 'City:' https://itslinuxfoss.com
How to Print the Server Response Using the cURL?
To print the server response, including the list of the cookies and the resource size, use the “-i” option of the curl command:
$ curl -i https://itslinuxfoss.com
That’s all about managing the HTTPS headers with the cURL command.
The cURL command is used in Linux to transfer data between two servers, and the HTTPS Headers are responsible for sharing the additional data. This post has presented a detailed guide about the cURL headers and how to manage them.