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_COOKIE 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLINFO_COOKIELIST (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIEFILE (3) 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIEJAR (3) 11*6236dae4SAndroid Build Coastguard Worker - CURLOPT_COOKIELIST (3) 12*6236dae4SAndroid Build Coastguard Worker - CURLOPT_HTTPHEADER (3) 13*6236dae4SAndroid Build Coastguard WorkerProtocol: 14*6236dae4SAndroid Build Coastguard Worker - HTTP 15*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1 16*6236dae4SAndroid Build Coastguard Worker--- 17*6236dae4SAndroid Build Coastguard Worker 18*6236dae4SAndroid Build Coastguard Worker# NAME 19*6236dae4SAndroid Build Coastguard Worker 20*6236dae4SAndroid Build Coastguard WorkerCURLOPT_COOKIE - HTTP Cookie header 21*6236dae4SAndroid Build Coastguard Worker 22*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard Worker~~~c 25*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIE, char *cookie); 28*6236dae4SAndroid Build Coastguard Worker~~~ 29*6236dae4SAndroid Build Coastguard Worker 30*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 31*6236dae4SAndroid Build Coastguard Worker 32*6236dae4SAndroid Build Coastguard WorkerPass a pointer to a null-terminated string as parameter. It is used to set one 33*6236dae4SAndroid Build Coastguard Workeror more cookies in the HTTP request. The format of the string should be 34*6236dae4SAndroid Build Coastguard WorkerNAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookie 35*6236dae4SAndroid Build Coastguard Workershould contain. 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard WorkerTo set multiple cookies, set them all using a single option concatenated like 38*6236dae4SAndroid Build Coastguard Workerthis: "name1=content1; name2=content2;" etc. libcurl does not syntax check the 39*6236dae4SAndroid Build Coastguard Workerdata but assumes the application gives it what it needs to send. 40*6236dae4SAndroid Build Coastguard Worker 41*6236dae4SAndroid Build Coastguard WorkerThis option sets the cookie header explicitly in the outgoing request(s). If 42*6236dae4SAndroid Build Coastguard Workermultiple requests are done due to authentication, followed redirections or 43*6236dae4SAndroid Build Coastguard Workersimilar, they all get this cookie passed on. 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard WorkerThe cookies set by this option are separate from the internal cookie storage 46*6236dae4SAndroid Build Coastguard Workerheld by the cookie engine and they are not be modified by it. If you enable 47*6236dae4SAndroid Build Coastguard Workerthe cookie engine and either you have imported a cookie of the same name (e.g. 48*6236dae4SAndroid Build Coastguard Worker'foo') or the server has set one, it has no effect on the cookies you set 49*6236dae4SAndroid Build Coastguard Workerhere. A request to the server sends both the 'foo' held by the cookie engine 50*6236dae4SAndroid Build Coastguard Workerand the 'foo' held by this option. To set a cookie that is instead held by the 51*6236dae4SAndroid Build Coastguard Workercookie engine and can be modified by the server use CURLOPT_COOKIELIST(3). 52*6236dae4SAndroid Build Coastguard Worker 53*6236dae4SAndroid Build Coastguard WorkerSince this custom cookie is appended to the Cookie: header in addition to any 54*6236dae4SAndroid Build Coastguard Workercookies set by the cookie engine, there is a risk that the header ends up too 55*6236dae4SAndroid Build Coastguard Workerlong and thereby getting the entire request rejected by the server. 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard WorkerThe application does not have to keep the string around after setting this 58*6236dae4SAndroid Build Coastguard Workeroption. 59*6236dae4SAndroid Build Coastguard Worker 60*6236dae4SAndroid Build Coastguard WorkerUsing this option multiple times makes the last set string override the 61*6236dae4SAndroid Build Coastguard Workerprevious ones. Set it to NULL to disable its use again. 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard WorkerThis option does not enable the cookie engine. Use CURLOPT_COOKIEFILE(3) or 64*6236dae4SAndroid Build Coastguard WorkerCURLOPT_COOKIEJAR(3) to enable parsing and sending cookies automatically. 65*6236dae4SAndroid Build Coastguard Worker 66*6236dae4SAndroid Build Coastguard Worker# DEFAULT 67*6236dae4SAndroid Build Coastguard Worker 68*6236dae4SAndroid Build Coastguard WorkerNULL, no cookies 69*6236dae4SAndroid Build Coastguard Worker 70*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 71*6236dae4SAndroid Build Coastguard Worker 72*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 73*6236dae4SAndroid Build Coastguard Worker 74*6236dae4SAndroid Build Coastguard Worker~~~c 75*6236dae4SAndroid Build Coastguard Workerint main(void) 76*6236dae4SAndroid Build Coastguard Worker{ 77*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 78*6236dae4SAndroid Build Coastguard Worker if(curl) { 79*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 80*6236dae4SAndroid Build Coastguard Worker 81*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_COOKIE, "tool=curl; fun=yes;"); 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard Worker curl_easy_perform(curl); 84*6236dae4SAndroid Build Coastguard Worker } 85*6236dae4SAndroid Build Coastguard Worker} 86*6236dae4SAndroid Build Coastguard Worker~~~ 87*6236dae4SAndroid Build Coastguard Worker 88*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 89*6236dae4SAndroid Build Coastguard Worker 90*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 91*6236dae4SAndroid Build Coastguard Worker 92*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if HTTP is enabled, CURLE_UNKNOWN_OPTION if not, or 93*6236dae4SAndroid Build Coastguard WorkerCURLE_OUT_OF_MEMORY if there was insufficient heap space. 94