1CURLOPT_COOKIELIST(3) curl_easy_setopt options CURLOPT_COOKIELIST(3)
2
3
4
6 CURLOPT_COOKIELIST - add to or manipulate cookies held in memory
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIELIST,
12 char *cookie);
13
15 Pass a char * to a cookie string.
16
17 Such a cookie can be either a single line in Netscape / Mozilla format
18 or just regular HTTP-style header (Set-Cookie: ...) format. This will
19 also enable the cookie engine. This adds that single cookie to the in‐
20 ternal cookie store.
21
22 Exercise caution if you are using this option and multiple transfers
23 may occur. If you use the Set-Cookie format and don't specify a domain
24 then the cookie is sent for any domain (even after redirects are fol‐
25 lowed) and cannot be modified by a server-set cookie. If a server sets
26 a cookie of the same name (or maybe you've imported one) then both will
27 be sent on a future transfer to that server, likely not what you in‐
28 tended. To address these issues set a domain in Set-Cookie (doing that
29 will include sub-domains) or use the Netscape format as shown in EXAM‐
30 PLE.
31
32 Additionally, there are commands available that perform actions if you
33 pass in these exact strings:
34
35 ALL erases all cookies held in memory
36
37
38 SESS erases all session cookies held in memory
39
40
41 FLUSH writes all known cookies to the file specified by CURLOPT_COOK‐
42 IEJAR(3)
43
44
45 RELOAD loads all cookies from the files specified by CURLOPT_COOK‐
46 IEFILE(3)
47
48
50 NULL
51
53 HTTP
54
56 /* This example shows an inline import of a cookie in Netscape format.
57 You can set the cookie as HttpOnly to prevent XSS attacks by prepending
58 #HttpOnly_ to the hostname. That may be useful if the cookie will later
59 be imported by a browser.
60 */
61
62 #define SEP "\t" /* Tab separates the fields */
63
64 char *my_cookie =
65 "example.com" /* Hostname */
66 SEP "FALSE" /* Include subdomains */
67 SEP "/" /* Path */
68 SEP "FALSE" /* Secure */
69 SEP "0" /* Expiry in epoch time format. 0 == Session */
70 SEP "foo" /* Name */
71 SEP "bar"; /* Value */
72
73 /* my_cookie is imported immediately via CURLOPT_COOKIELIST.
74 */
75 curl_easy_setopt(curl, CURLOPT_COOKIELIST, my_cookie);
76
77 /* The list of cookies in cookies.txt will not be imported until right
78 before a transfer is performed. Cookies in the list that have the same
79 hostname, path and name as in my_cookie are skipped. That is because
80 libcurl has already imported my_cookie and it's considered a "live"
81 cookie. A live cookie won't be replaced by one read from a file.
82 */
83 curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt"); /* import */
84
85 /* Cookies are exported after curl_easy_cleanup is called. The server
86 may have added, deleted or modified cookies by then. The cookies that
87 were skipped on import are not exported.
88 */
89 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt"); /* export */
90
91 curl_easy_perform(curl); /* cookies imported from cookies.txt */
92
93 curl_easy_cleanup(curl); /* cookies exported to cookies.txt */
94
96 The cookie file format and general cookie concepts in curl are de‐
97 scribed in the HTTP-COOKIES.md file, also hosted online here:
98 https://curl.se/docs/http-cookies.html
99
101 ALL was added in 7.14.1
102
103 SESS was added in 7.15.4
104
105 FLUSH was added in 7.17.1
106
107 RELOAD was added in 7.39.0
108
110 Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if
111 not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space.
112
114 CURLOPT_COOKIEFILE(3), CURLOPT_COOKIEJAR(3), CURLOPT_COOKIE(3),
115 CURLINFO_COOKIELIST(3),
116
117
118
119libcurl 7.79.1 November 04, 2020 CURLOPT_COOKIELIST(3)