Curl set cookie

Curl is a command-line tool for transferring data between a local computer and a remote server

1 min read
By myfreax
Curl set cookie
Curl set cookie

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+Tto 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 and send cookies

When using the Curl command to make an HTTP request, by default the Curl command does not send or store any cookie information.

Sometimes you may need to specify a cookie to initiate an HTTP request to access server resources.

The -b option of the Curl command allows setting cookie data to be sent to the server. To set a cookie, follow the -b option with the cookie string or the file name containing the cookie data.

For example, if you want to download the rpm file of Oracle Java JDK, you need to send Cookie key-value pairs oraclelicense=a.

curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.rpm

Related Articles