1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_COOKIEJAR 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIE (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIEFILE (3) 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIELIST (3) 11*6236dae4SAndroid Build Coastguard WorkerProtocol: 12*6236dae4SAndroid Build Coastguard Worker - HTTP 13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.9 14*6236dae4SAndroid Build Coastguard Worker--- 15*6236dae4SAndroid Build Coastguard Worker 16*6236dae4SAndroid Build Coastguard Worker# NAME 17*6236dae4SAndroid Build Coastguard Worker 18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_COOKIEJAR - filename to store cookies to 19*6236dae4SAndroid Build Coastguard Worker 20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 21*6236dae4SAndroid Build Coastguard Worker 22*6236dae4SAndroid Build Coastguard Worker~~~c 23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 24*6236dae4SAndroid Build Coastguard Worker 25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEJAR, char *filename); 26*6236dae4SAndroid Build Coastguard Worker~~~ 27*6236dae4SAndroid Build Coastguard Worker 28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 29*6236dae4SAndroid Build Coastguard Worker 30*6236dae4SAndroid Build Coastguard WorkerPass a *filename* as a char *, null-terminated. This makes libcurl write all 31*6236dae4SAndroid Build Coastguard Workerinternally known cookies to the specified file when curl_easy_cleanup(3) is 32*6236dae4SAndroid Build Coastguard Workercalled. If no cookies are kept in memory at that time, no file is created. 33*6236dae4SAndroid Build Coastguard WorkerSpecify "-" as filename to instead have the cookies written to stdout. Using 34*6236dae4SAndroid Build Coastguard Workerthis option also enables cookies for this session, so if you for example 35*6236dae4SAndroid Build Coastguard Workerfollow a redirect it makes matching cookies get sent accordingly. 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard WorkerNote that libcurl does not read any cookies from the cookie jar specified with 38*6236dae4SAndroid Build Coastguard Workerthis option. To read cookies from a file, use CURLOPT_COOKIEFILE(3). 39*6236dae4SAndroid Build Coastguard Worker 40*6236dae4SAndroid Build Coastguard WorkerIf the cookie jar file cannot be created or written to (when the 41*6236dae4SAndroid Build Coastguard Workercurl_easy_cleanup(3) is called), libcurl does not and cannot report an error 42*6236dae4SAndroid Build Coastguard Workerfor this. Using CURLOPT_VERBOSE(3) or CURLOPT_DEBUGFUNCTION(3) displays a 43*6236dae4SAndroid Build Coastguard Workerwarning, but that is the only visible feedback you get about this possibly 44*6236dae4SAndroid Build Coastguard Workerlethal situation. 45*6236dae4SAndroid Build Coastguard Worker 46*6236dae4SAndroid Build Coastguard WorkerCookies are imported in the Set-Cookie format without a domain name are not 47*6236dae4SAndroid Build Coastguard Workerexported by this option. 48*6236dae4SAndroid Build Coastguard Worker 49*6236dae4SAndroid Build Coastguard WorkerThe application does not have to keep the string around after setting this 50*6236dae4SAndroid Build Coastguard Workeroption. 51*6236dae4SAndroid Build Coastguard Worker 52*6236dae4SAndroid Build Coastguard WorkerUsing this option multiple times makes the last set string override the 53*6236dae4SAndroid Build Coastguard Workerprevious ones. Set it to NULL to disable its use again. 54*6236dae4SAndroid Build Coastguard Worker 55*6236dae4SAndroid Build Coastguard Worker# DEFAULT 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard WorkerNULL 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 60*6236dae4SAndroid Build Coastguard Worker 61*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker~~~c 64*6236dae4SAndroid Build Coastguard Workerint main(void) 65*6236dae4SAndroid Build Coastguard Worker{ 66*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 67*6236dae4SAndroid Build Coastguard Worker if(curl) { 68*6236dae4SAndroid Build Coastguard Worker CURLcode res; 69*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker /* export cookies to this file when closing the handle */ 72*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt"); 73*6236dae4SAndroid Build Coastguard Worker 74*6236dae4SAndroid Build Coastguard Worker res = curl_easy_perform(curl); 75*6236dae4SAndroid Build Coastguard Worker 76*6236dae4SAndroid Build Coastguard Worker /* close the handle, write the cookies */ 77*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 78*6236dae4SAndroid Build Coastguard Worker } 79*6236dae4SAndroid Build Coastguard Worker} 80*6236dae4SAndroid Build Coastguard Worker~~~ 81*6236dae4SAndroid Build Coastguard Worker 82*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 83*6236dae4SAndroid Build Coastguard Worker 84*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 85*6236dae4SAndroid Build Coastguard Worker 86*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if HTTP is supported, CURLE_UNKNOWN_OPTION if not, or 87*6236dae4SAndroid Build Coastguard WorkerCURLE_OUT_OF_MEMORY if there was insufficient heap space. 88