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_COOKIEFILE 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_COOKIEJAR (3) 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIESESSION (3) 11*6236dae4SAndroid Build Coastguard WorkerProtocol: 12*6236dae4SAndroid Build Coastguard Worker - HTTP 13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1 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_COOKIEFILE - filename to read cookies from 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_COOKIEFILE, 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 pointer to a null-terminated string as parameter. It should point to 31*6236dae4SAndroid Build Coastguard Workerthe filename of your file holding cookie data to read. The cookie data can be 32*6236dae4SAndroid Build Coastguard Workerin either the old Netscape / Mozilla cookie data format or just regular HTTP 33*6236dae4SAndroid Build Coastguard Workerheaders (Set-Cookie style) dumped to a file. 34*6236dae4SAndroid Build Coastguard Worker 35*6236dae4SAndroid Build Coastguard WorkerIt also enables the cookie engine, making libcurl parse and send cookies on 36*6236dae4SAndroid Build Coastguard Workersubsequent requests with this handle. 37*6236dae4SAndroid Build Coastguard Worker 38*6236dae4SAndroid Build Coastguard WorkerBy passing the empty string ("") to this option, you enable the cookie engine 39*6236dae4SAndroid Build Coastguard Workerwithout reading any initial cookies. If you tell libcurl the filename is "-" 40*6236dae4SAndroid Build Coastguard Worker(just a single minus sign), libcurl instead reads from stdin. 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard WorkerThis option only **reads** cookies. To make libcurl write cookies to file, 43*6236dae4SAndroid Build Coastguard Workersee CURLOPT_COOKIEJAR(3). 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard WorkerIf you read cookies from a plain HTTP headers file and it does not specify a 46*6236dae4SAndroid Build Coastguard Workerdomain in the Set-Cookie line, then the cookie is not sent since the cookie 47*6236dae4SAndroid Build Coastguard Workerdomain cannot match the target URL's. To address this, set a domain in 48*6236dae4SAndroid Build Coastguard WorkerSet-Cookie line (doing that includes subdomains) or preferably: use the 49*6236dae4SAndroid Build Coastguard WorkerNetscape format. 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard WorkerThe application does not have to keep the string around after setting this 52*6236dae4SAndroid Build Coastguard Workeroption. 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerIf you use this option multiple times, you add more files to read cookies 55*6236dae4SAndroid Build Coastguard Workerfrom. Setting this option to NULL disables the cookie engine and clears the 56*6236dae4SAndroid Build Coastguard Workerlist of files to read cookies from. 57*6236dae4SAndroid Build Coastguard Worker 58*6236dae4SAndroid Build Coastguard Worker# SECURITY 59*6236dae4SAndroid Build Coastguard Worker 60*6236dae4SAndroid Build Coastguard WorkerThis document previously mentioned how specifying a non-existing file can also 61*6236dae4SAndroid Build Coastguard Workerenable the cookie engine. While true, we strongly advise against using that 62*6236dae4SAndroid Build Coastguard Workermethod as it is too hard to be sure that files that stay that way in the long 63*6236dae4SAndroid Build Coastguard Workerrun. 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard Worker# DEFAULT 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard WorkerNULL 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard Worker~~~c 74*6236dae4SAndroid Build Coastguard Workerint main(void) 75*6236dae4SAndroid Build Coastguard Worker{ 76*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 77*6236dae4SAndroid Build Coastguard Worker if(curl) { 78*6236dae4SAndroid Build Coastguard Worker CURLcode res; 79*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 80*6236dae4SAndroid Build Coastguard Worker 81*6236dae4SAndroid Build Coastguard Worker /* get cookies from an existing file */ 82*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt"); 83*6236dae4SAndroid Build Coastguard Worker 84*6236dae4SAndroid Build Coastguard Worker res = curl_easy_perform(curl); 85*6236dae4SAndroid Build Coastguard Worker 86*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 87*6236dae4SAndroid Build Coastguard Worker } 88*6236dae4SAndroid Build Coastguard Worker} 89*6236dae4SAndroid Build Coastguard Worker~~~ 90*6236dae4SAndroid Build Coastguard Worker 91*6236dae4SAndroid Build Coastguard Worker# Cookie file format 92*6236dae4SAndroid Build Coastguard Worker 93*6236dae4SAndroid Build Coastguard WorkerThe cookie file format and general cookie concepts in curl are described 94*6236dae4SAndroid Build Coastguard Workeronline here: https://curl.se/docs/http-cookies.html 95*6236dae4SAndroid Build Coastguard Worker 96*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 97*6236dae4SAndroid Build Coastguard Worker 98*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 99*6236dae4SAndroid Build Coastguard Worker 100*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not. 101