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