Curl set header
Curl is a command-line tool for transferring data between a local computer and a remote server
Curl is a command-line tool for transferring data between a local computer and a remote server.
When using curl you can download or upload data using protocols such as HTTP, HTTPS, SCP , SFTP and FTP .
The Curl command is pre-installed on most Linux distributions. To check if your Linux distribution has Curl installed, press the shortcut key CTRL+ALT+T
to open Terminal, type curl
and press Enter.
If curl is installed, the system will print curl: try 'curl --help' or 'curl --manual' for more information
.
Install Curl
Otherwise, the terminal prints the message curl command not found. If you don't have Curl installed, you can install it using your distribution's package manager.
If your computer is running a Debian-based Linux distribution such as Ubuntu, Linux Mint, etc. Please run sudo apt install curl
to install Curl.
If your computer is running a Redhat-based Linux distribution, such as CentOS, Fedora, etc. Please run sudo yum install curl
to install Curl.
sudo yum install curl
sudo apt install curl
Set HTTP request header
If you want to send the Header to the server, you can use the -H
/ --header
option of the Curl command, which allows you to specify the key Key and Value of the request header.
Spaces must be used between the Key and Value of the Header, and the request header must be wrapped in double quotes to avoid shell interpretation.
Multiple -H
/ --header
options can be used at the same time to specify the Key and Value of multiple request headers. You can see that the command below will send multiple request headers.
The first request header sets the content type Content-Type: application/json
, and the second request header sends website: myfreax.com
.
curl -X POST -H "Content-Type: application/json" -H "website: myfreax.com" -d '{"email":"web@myfreax.com","website":"myfreax.com"}' http://127.0.0.1:3000/site