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