1CURLOPT_COOKIEFILE(3) curl_easy_setopt options CURLOPT_COOKIEFILE(3)
2
3
4
6 CURLOPT_COOKIEFILE - file name to read cookies from
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEFILE, char *file‐
12 name);
13
15 Pass a pointer to a null-terminated string as parameter. It should
16 point to the file name of your file holding cookie data to read. The
17 cookie data can be in either the old Netscape / Mozilla cookie data
18 format or just regular HTTP headers (Set-Cookie style) dumped to a
19 file.
20
21 It also enables the cookie engine, making libcurl parse and send cook‐
22 ies on subsequent requests with this handle.
23
24 Given an empty or non-existing file or by passing the empty string ("")
25 to this option, you can enable the cookie engine without reading any
26 initial cookies. If you tell libcurl the file name is "-" (just a sin‐
27 gle minus sign), libcurl will instead read from stdin.
28
29 This option only reads cookies. To make libcurl write cookies to file,
30 see CURLOPT_COOKIEJAR(3).
31
32 Exercise caution if you are using this option and multiple transfers
33 may occur. If you use the Set-Cookie format and don't specify a domain
34 then the cookie is sent for any domain (even after redirects are fol‐
35 lowed) and cannot be modified by a server-set cookie. If a server sets
36 a cookie of the same name then both will be sent on a future transfer
37 to that server, likely not what you intended. To address these issues
38 set a domain in Set-Cookie (doing that will include sub-domains) or use
39 the Netscape format.
40
41 If you use this option multiple times, you just add more files to read.
42 Subsequent files will add more cookies.
43
44 The application does not have to keep the string around after setting
45 this option.
46
48 NULL
49
51 HTTP
52
54 CURL *curl = curl_easy_init();
55 if(curl) {
56 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
57
58 /* get cookies from an existing file */
59 curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
60
61 ret = curl_easy_perform(curl);
62
63 curl_easy_cleanup(curl);
64 }
65
67 The cookie file format and general cookie concepts in curl are de‐
68 scribed in the HTTP-COOKIES.md file, also hosted online here:
69 https://curl.se/docs/http-cookies.html
70
72 As long as HTTP is supported
73
75 Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
76
78 CURLOPT_COOKIE(3), CURLOPT_COOKIEJAR(3),
79
80
81
82libcurl 7.76.1 November 04, 2020 CURLOPT_COOKIEFILE(3)