CURLOPT_COOKIEJAR.md (2572B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_COOKIEJAR 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_COOKIE (3) 9 - CURLOPT_COOKIEFILE (3) 10 - CURLOPT_COOKIELIST (3) 11 Protocol: 12 - HTTP 13 Added-in: 7.9 14 --- 15 16 # NAME 17 18 CURLOPT_COOKIEJAR - filename to store cookies to 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEJAR, char *filename); 26 ~~~ 27 28 # DESCRIPTION 29 30 Pass a *filename* as a char *, null-terminated. This makes libcurl write all 31 internally known cookies to the specified file when curl_easy_cleanup(3) is 32 called. If no cookies are kept in memory at that time, no file is created. 33 Specify "-" as filename to instead have the cookies written to stdout. Using 34 this option also enables cookies for this session, so if you for example 35 follow a redirect it makes matching cookies get sent accordingly. 36 37 Note that libcurl does not read any cookies from the cookie jar specified with 38 this option. To read cookies from a file, use CURLOPT_COOKIEFILE(3). 39 40 If the cookie jar file cannot be created or written to (when the 41 curl_easy_cleanup(3) is called), libcurl does not and cannot report an error 42 for this. Using CURLOPT_VERBOSE(3) or CURLOPT_DEBUGFUNCTION(3) displays a 43 warning, but that is the only visible feedback you get about this possibly 44 lethal situation. 45 46 Cookies are imported in the Set-Cookie format without a domain name are not 47 exported by this option. 48 49 The application does not have to keep the string around after setting this 50 option. 51 52 Using this option multiple times makes the last set string override the 53 previous ones. Set it to NULL to disable its use again. 54 55 # SECURITY CONCERNS 56 57 libcurl cannot fully protect against attacks where an attacker has write 58 access to the same directory where it is directed to save files. This is 59 particularly sensitive if you save files using elevated privileges. 60 61 # DEFAULT 62 63 NULL 64 65 # %PROTOCOLS% 66 67 # EXAMPLE 68 69 ~~~c 70 int main(void) 71 { 72 CURL *curl = curl_easy_init(); 73 if(curl) { 74 CURLcode res; 75 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 76 77 /* export cookies to this file when closing the handle */ 78 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt"); 79 80 res = curl_easy_perform(curl); 81 82 /* close the handle, write the cookies */ 83 curl_easy_cleanup(curl); 84 } 85 } 86 ~~~ 87 88 # %AVAILABILITY% 89 90 # RETURN VALUE 91 92 curl_easy_setopt(3) returns a CURLcode indicating success or error. 93 94 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 95 libcurl-errors(3).