Cookies are small pieces of data that are stored on a user's computer by a web browser. They are used to store information about the user's session, such as login credentials, shopping cart contents, or user preferences. Cookies are sent to the server with each request, allowing the server to identify the user and provide a personalized experience.
You can create a cookie file manually to use with cURL. You can also save cookies from a browser session and edit them manually to create a cookie file for cURL.
cURL supports the Netscape cookie file format. This format is used by most browsers, including Chrome, Firefox, and Safari. The cookie file is a plain text file with one cookie per line. Each line contains seven tab-separated fields, such as domain, path, and expiration time.
# Domain Tailmatch Path Secure Expiry Name Value
# Domain Tailmatch Path Secure Expiry Name Value .example.com
The domain should begin with a dot, which indicates that the cookie is valid for subdomains as well. If not, the cookie is valid only for that specific domain.
# Domain Tailmatch Path Secure Expiry Name Value .example.com TRUE
“TRUE” means the cookie is accessible by any machine within the specified domain. “FALSE” indicates the cookie is restricted only to the specified domain.
# Domain Tailmatch Path Secure Expiry Name Value .example.com TRUE /
The path specifies the directory or directories that the cookie is valid for. A path of “/” means the cookie is available for the entire website.
# Domain Tailmatch Path Secure Expiry Name Value .example.com TRUE / TRUE
If set to TRUE, the cookie will only be sent over secure connections like HTTPS. If set to FALSE, the cookie can be sent over any connection.
# Domain Tailmatch Path Secure Expiry Name Value .example.com TRUE / TRUE 1672531199
This UNIX timestamp determines when the cookie will expire. After this time, the cookie will no longer be sent in requests to the server.
# Domain Tailmatch Path Secure Expiry Name Value .example.com TRUE / TRUE 1672531199 SessionID
This is the identifier for the cookie and is used by the server to retrieve its value.
# Domain Tailmatch Path Secure Expiry Name Value .example.com TRUE / TRUE 1672531199 SessionID 1234567890abcdef
The value holds the actual data stored for the cookie and is sent to the server in each request.
# Domain Tailmatch Path Secure Expiry Name Value .example.com TRUE / TRUE 1672531199 SessionID 1234567890abcdef .example.com TRUE / TRUE 1672531199 UserID myid
Ensure cookies are in the correct order; entries above take precedence.
$ curl -b "manual-cookies.txt" http://www.example.com/dashboard
Related: How to use cookies in cURL requests
Comment anonymously. Login not required.