1CURLOPT_COOKIEJAR(3) curl_easy_setopt options CURLOPT_COOKIEJAR(3)
2
3
4
6 CURLOPT_COOKIEJAR - file name to store cookies to
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEJAR, char *filename);
12
14 Pass a filename as char *, null-terminated. This will make libcurl
15 write all internally known cookies to the specified file when
16 curl_easy_cleanup(3) is called. If no cookies are known, no file will
17 be created. Specify "-" as filename to instead have the cookies written
18 to stdout. Using this option also enables cookies for this session, so
19 if you for example follow a location it will make matching cookies get
20 sent accordingly.
21
22 Note that libcurl does not read any cookies from the cookie jar. If you
23 want to read cookies from a file, use CURLOPT_COOKIEFILE(3).
24
25 If the cookie jar file cannot be created or written to (when the
26 curl_easy_cleanup(3) is called), libcurl will not and cannot report an
27 error for this. Using CURLOPT_VERBOSE(3) or CURLOPT_DEBUGFUNCTION(3)
28 will get a warning to display, but that is the only visible feedback
29 you get about this possibly lethal situation.
30
31 Since 7.43.0 cookies that were imported in the Set-Cookie format with‐
32 out a domain name are not exported by this option.
33
34 The application does not have to keep the string around after setting
35 this option.
36
38 NULL
39
41 HTTP
42
44 CURL *curl = curl_easy_init();
45 if(curl) {
46 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
47
48 /* export cookies to this file when closing the handle */
49 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt");
50
51 ret = curl_easy_perform(curl);
52
53 /* close the handle, write the cookies! */
54 curl_easy_cleanup(curl);
55 }
56
58 Along with HTTP
59
61 Returns CURLE_OK if HTTP is supported, CURLE_UNKNOWN_OPTION if not, or
62 CURLE_OUT_OF_MEMORY if there was insufficient heap space.
63
65 CURLOPT_COOKIEFILE(3), CURLOPT_COOKIE(3), CURLOPT_COOKIELIST(3),
66
67
68
69libcurl 8.0.1 January 02, 2023 CURLOPT_COOKIEJAR(3)