Cookies are passed to Curl with the --cookie "Name=Value" command line parameter. Curl automatically converts the given parameter into the Cookie: Name=Value request header. Cookies can be sent by any HTTP method, including GET, POST, PUT, and DELETE, and with any data, including JSON, web forms, and file uploads. In this Curl Send Cookies example, we are sending cookies to the ReqBin echo URL. Click Run to execute Curl Send Cookies example online and see results. The Python code was automatically generated for the Curl Send Cookies example.
The Curl is a command-line tool available for Linux, Windows, and macOS and a cross-platform library (libcurl) that can be used with almost any application written in nearly any programming language. Curl uses URL syntax to transfer data to and from servers. With Curl, you can upload or download data, submit web forms, and make API requests using over 25 protocols, including HTTP, HTTPS, FTP, and SFTP.
What is Cookie?
Cookies are small blocks of data sent from a website and stored by a web browser on a user's computer. Cookies are placed on the device used to access the website (computer, mobile phone, etc.). Several cookies may be placed on the same computer during a session. Browsers send cookies back to the server with each subsequent request, allowing the server to determine if the request came from the same browser or not.
Cookies enable web servers to store state information on a user's device or track a user's online activity. The data stored in cookies are created by the server when it connects to the server. This data is tagged with an identifier that is unique to user and user's computer. Cookies are primarily used for user session management, user tracking, and personalization.
Curl Send Cookies Example
GET /echo HTTP/1.1
How set Cookie with Curl?
The general form of the Curl command for sending a Cookies request is as follows:
Curl Send Cookies Syntax
curl --cookie "Name=Value" [URL]
What is cookie-jar?
The -c (or --cookie-jar) command-line option specifies the filename where Curl should write all cookies after the operation completes. Curl will report to the specified file all the cookies from its in-memory cookie store at the end of the process. If there are no cookies, Curl will not create the specified file. If you include a dash "-" for a filename, Curl will write cookies to standard output.
Curl Save Cookies Syntax
curl -c cookies.txt [URL]
How to set cookies for Curl?
You can use the -b (or --cookie) command-line switch to pass cookies to Curl.
Curl Send Cookies Syntax
curl -b "name=value" [URL]
How to use Сookies with Libcurl?