1CURLOPT_COOKIEFILE(3)               libcurl              CURLOPT_COOKIEFILE(3)
2
3
4

NAME

6       CURLOPT_COOKIEFILE - file name to read cookies from
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEFILE, char *filename);
12

DESCRIPTION

14       Pass  a  pointer  to  a  null-terminated string as parameter. It should
15       point to the file name of your file holding cookie data  to  read.  The
16       cookie  data  can  be  in either the old Netscape / Mozilla cookie data
17       format or just regular HTTP headers  (Set-Cookie  style)  dumped  to  a
18       file.
19
20       It  also enables the cookie engine, making libcurl parse and send cook‐
21       ies on subsequent requests with this handle.
22
23       By passing the empty string ("") to this option, you enable the  cookie
24       engine  without  reading  any  initial cookies. If you tell libcurl the
25       file name is "-" (just a single minus sign), libcurl will instead  read
26       from stdin.
27
28       This  option only reads cookies. To make libcurl write cookies to file,
29       see CURLOPT_COOKIEJAR(3).
30
31       If you use the Set-Cookie file format and do not specify a domain  then
32       the  cookie  is  not sent since the domain will never match. To address
33       this, set a domain in Set-Cookie line (doing that will include  sub-do‐
34       mains) or preferably: use the Netscape format.
35
36       If you use this option multiple times, you just add more files to read.
37       Subsequent files will add more cookies.
38
39       The application does not have to keep the string around  after  setting
40       this option.
41
42       Setting  this option to NULL will (since 7.77.0) explicitly disable the
43       cookie engine and clear the list of files to read cookies from.
44

SECURITY

46       This document previously mentioned how specifying a  non-existing  file
47       can  also  enable  the  cookie  engine.  While true, we strongly advise
48       against using that method as it is too hard to be sure what files  will
49       stay that way in the long run.
50

DEFAULT

52       NULL
53

PROTOCOLS

55       HTTP
56

EXAMPLE

58       CURL *curl = curl_easy_init();
59       if(curl) {
60         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
61
62         /* get cookies from an existing file */
63         curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
64
65         ret = curl_easy_perform(curl);
66
67         curl_easy_cleanup(curl);
68       }
69
71       The  cookie  file  format  and  general cookie concepts in curl are de‐
72       scribed online here: https://curl.se/docs/http-cookies.html
73

AVAILABILITY

75       As long as HTTP is supported
76

RETURN VALUE

78       Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
79

SEE ALSO

81       CURLOPT_COOKIE(3), CURLOPT_COOKIEJAR(3),
82
83
84
85ibcurl 8.2.1                    April 26, 2023           CURLOPT_COOKIEFILE(3)
Impressum