1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_COOKIE 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_COOKIELIST (3) 9 - CURLOPT_COOKIEFILE (3) 10 - CURLOPT_COOKIEJAR (3) 11 - CURLOPT_COOKIELIST (3) 12 - CURLOPT_HTTPHEADER (3) 13Protocol: 14 - HTTP 15--- 16 17# NAME 18 19CURLOPT_COOKIE - HTTP Cookie header 20 21# SYNOPSIS 22 23~~~c 24#include <curl/curl.h> 25 26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIE, char *cookie); 27~~~ 28 29# DESCRIPTION 30 31Pass a pointer to a null-terminated string as parameter. It is used to set one 32or more cookies in the HTTP request. The format of the string should be 33NAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookie 34should contain. 35 36To set multiple cookies, set them all using a single option concatenated like 37this: "name1=content1; name2=content2;" etc. 38 39This option sets the cookie header explicitly in the outgoing request(s). If 40multiple requests are done due to authentication, followed redirections or 41similar, they all get this cookie passed on. 42 43The cookies set by this option are separate from the internal cookie storage 44held by the cookie engine and they are not be modified by it. If you enable 45the cookie engine and either you have imported a cookie of the same name 46(e.g. 'foo') or the server has set one, it has no effect on the cookies you 47set here. A request to the server sends both the 'foo' held by the cookie 48engine and the 'foo' held by this option. To set a cookie that is instead held 49by the cookie engine and can be modified by the server use 50CURLOPT_COOKIELIST(3). 51 52Using this option multiple times makes the last set string override the 53previous ones. 54 55This option does not enable the cookie engine. Use CURLOPT_COOKIEFILE(3) 56or CURLOPT_COOKIEJAR(3) to enable parsing and sending cookies 57automatically. 58 59The application does not have to keep the string around after setting this 60option. 61 62If libcurl is built with PSL (*Public Suffix List*) support, it detects and 63discards cookies that are specified for such suffix domains that should not be 64allowed to have cookies. If libcurl is *not* built with PSL support, it has no 65ability to stop super cookies. PSL support is identified by the 66**CURL_VERSION_PSL** feature bit returned by curl_version_info(3). 67 68# DEFAULT 69 70NULL, no cookies 71 72# EXAMPLE 73 74~~~c 75int main(void) 76{ 77 CURL *curl = curl_easy_init(); 78 if(curl) { 79 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 80 81 curl_easy_setopt(curl, CURLOPT_COOKIE, "tool=curl; fun=yes;"); 82 83 curl_easy_perform(curl); 84 } 85} 86~~~ 87 88# AVAILABILITY 89 90If HTTP is enabled 91 92# RETURN VALUE 93 94Returns CURLE_OK if HTTP is enabled, CURLE_UNKNOWN_OPTION if not, or 95CURLE_OUT_OF_MEMORY if there was insufficient heap space. 96