1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLINFO_COOKIELIST 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_COOKIELIST (3) 9 - curl_easy_getinfo (3) 10 - curl_easy_setopt (3) 11Protocol: 12 - HTTP 13Added-in: 7.14.1 14--- 15 16# NAME 17 18CURLINFO_COOKIELIST - get all known cookies 19 20# SYNOPSIS 21 22~~~c 23#include <curl/curl.h> 24 25CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_COOKIELIST, 26 struct curl_slist **cookies); 27~~~ 28 29# DESCRIPTION 30 31Pass a pointer to a 'struct curl_slist *' to receive a linked-list of all 32cookies curl knows (expired ones, too). Do not forget to call 33curl_slist_free_all(3) on the list after it has been used. If there are no 34cookies (cookies for the handle have not been enabled or simply none have been 35received) the 'struct curl_slist *' is made a NULL pointer. 36 37Since 7.43.0 cookies that were imported in the Set-Cookie format without a 38domain name are not exported by this option. 39 40# %PROTOCOLS% 41 42# EXAMPLE 43 44~~~c 45int main(void) 46{ 47 CURL *curl = curl_easy_init(); 48 if(curl) { 49 CURLcode res; 50 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 51 52 /* enable the cookie engine */ 53 curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); 54 55 res = curl_easy_perform(curl); 56 57 if(!res) { 58 /* extract all known cookies */ 59 struct curl_slist *cookies = NULL; 60 res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies); 61 if(!res && cookies) { 62 /* a linked list of cookies in cookie file format */ 63 struct curl_slist *each = cookies; 64 while(each) { 65 printf("%s\n", each->data); 66 each = each->next; 67 } 68 /* we must free these cookies when we are done */ 69 curl_slist_free_all(cookies); 70 } 71 } 72 curl_easy_cleanup(curl); 73 } 74} 75~~~ 76 77# %AVAILABILITY% 78 79# RETURN VALUE 80 81Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 82