Cookies store session data, preferences, and authentication states, enabling persistent, stateful HTTP interactions. The Netscape HTTP cookie file format standardizes how cookies are represented outside of a browser.
By creating a cookie file manually for cURL, it’s possible to control which cookies get sent during requests. This approach aids in automation, testing specific conditions, or replicating browser-like sessions without a full browser.
Understanding the Netscape HTTP cookie file format ensures compatibility with cURL and other tools. Precisely formatted entries for domain, path, and expiration enable reproducible and tailored HTTP interactions.
Related: How to save cookies from cURL request
Related: How to use cookies in cURL requests
Steps to create a cookie file for cURL:
- Open a text editor.
- Start with a comment line indicating the Netscape HTTP cookie file format.
# Netscape HTTP Cookie File # Domain Tailmatch Path Secure Expiry Name Value
- Specify the domain starting with a dot.
.example.com
A leading dot applies the cookie to all subdomains.
- Set the tailmatch field to TRUE or FALSE.
.example.com TRUE
TRUE allows the cookie to span subdomains.
- Define the path scope of the cookie.
.example.com TRUE /
“/” applies the cookie to the entire site.
- Specify if the cookie is secure.
.example.com TRUE / TRUE
TRUE means the cookie is only sent over HTTPS.
- Add an expiration time as a UNIX timestamp.
.example.com TRUE / TRUE 1672531199
This timestamp controls when the cookie expires.
- Provide the cookie’s name and value.
.example.com TRUE / TRUE 1672531199 SessionID 1234567890abcdef
Name-value pairs define the cookie’s data.
- Add more cookies as needed.
.example.com TRUE / TRUE 1672531199 UserID myid
Each line represents one cookie entry.
- Save the file with a .txt extension.
- Use the cookie file in cURL requests.
$ curl --cookie "manual-cookies.txt" "http://www.example.com/dashboard"
Related: How to use cookies in cURL requests

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.