CURLINFO_COOKIELIST.3 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. .\" generated by cd2nroff 0.1 from CURLINFO_COOKIELIST.md
  2. .TH CURLINFO_COOKIELIST 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLINFO_COOKIELIST \- get all known cookies
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_COOKIELIST,
  9. struct curl_slist **cookies);
  10. .fi
  11. .SH DESCRIPTION
  12. Pass a pointer to a \(aqstruct curl_slist *\(aq to receive a linked\-list of all
  13. cookies curl knows (expired ones, too). Do not forget to call
  14. \fIcurl_slist_free_all(3)\fP on the list after it has been used. If there are no
  15. cookies (cookies for the handle have not been enabled or simply none have been
  16. received) the \(aqstruct curl_slist *\(aq is made a NULL pointer.
  17. Since 7.43.0 cookies that were imported in the Set\-Cookie format without a
  18. domain name are not exported by this option.
  19. .SH PROTOCOLS
  20. This functionality affects http only
  21. .SH EXAMPLE
  22. .nf
  23. int main(void)
  24. {
  25. CURL *curl = curl_easy_init();
  26. if(curl) {
  27. CURLcode res;
  28. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  29. /* enable the cookie engine */
  30. curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
  31. res = curl_easy_perform(curl);
  32. if(!res) {
  33. /* extract all known cookies */
  34. struct curl_slist *cookies = NULL;
  35. res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
  36. if(!res && cookies) {
  37. /* a linked list of cookies in cookie file format */
  38. struct curl_slist *each = cookies;
  39. while(each) {
  40. printf("%s\\n", each->data);
  41. each = each->next;
  42. }
  43. /* we must free these cookies when we are done */
  44. curl_slist_free_all(cookies);
  45. }
  46. }
  47. curl_easy_cleanup(curl);
  48. }
  49. }
  50. .fi
  51. .SH AVAILABILITY
  52. Added in curl 7.14.1
  53. .SH RETURN VALUE
  54. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  55. .SH SEE ALSO
  56. .BR CURLOPT_COOKIELIST (3),
  57. .BR curl_easy_getinfo (3),
  58. .BR curl_easy_setopt (3)