1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_COOKIEJAR 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_COOKIE (3) 9 - CURLOPT_COOKIEFILE (3) 10 - CURLOPT_COOKIELIST (3) 11--- 12 13# NAME 14 15CURLOPT_COOKIEJAR - filename to store cookies to 16 17# SYNOPSIS 18 19~~~c 20#include <curl/curl.h> 21 22CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEJAR, char *filename); 23~~~ 24 25# DESCRIPTION 26 27Pass a *filename* as a char *, null-terminated. This makes libcurl write 28all internally known cookies to the specified file when 29curl_easy_cleanup(3) is called. If no cookies are kept in memory at that 30time, no file is created. Specify "-" as filename to instead have the cookies 31written to stdout. Using this option also enables cookies for this session, so 32if you for example follow a redirect it makes matching cookies get sent 33accordingly. 34 35Note that libcurl does not read any cookies from the cookie jar specified with 36this option. To read cookies from a file, use CURLOPT_COOKIEFILE(3). 37 38If the cookie jar file cannot be created or written to (when the 39curl_easy_cleanup(3) is called), libcurl does not and cannot report an 40error for this. Using CURLOPT_VERBOSE(3) or 41CURLOPT_DEBUGFUNCTION(3) displays a warning, but that is the only 42visible feedback you get about this possibly lethal situation. 43 44Cookies are imported in the Set-Cookie format without a domain name are not 45exported by this option. 46 47The application does not have to keep the string around after setting this 48option. 49 50# DEFAULT 51 52NULL 53 54# PROTOCOLS 55 56HTTP 57 58# EXAMPLE 59 60~~~c 61int main(void) 62{ 63 CURL *curl = curl_easy_init(); 64 if(curl) { 65 CURLcode res; 66 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 67 68 /* export cookies to this file when closing the handle */ 69 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt"); 70 71 res = curl_easy_perform(curl); 72 73 /* close the handle, write the cookies! */ 74 curl_easy_cleanup(curl); 75 } 76} 77~~~ 78 79# AVAILABILITY 80 81Along with HTTP 82 83# RETURN VALUE 84 85Returns CURLE_OK if HTTP is supported, CURLE_UNKNOWN_OPTION if not, or 86CURLE_OUT_OF_MEMORY if there was insufficient heap space. 87