CURLOPT_COOKIE.3 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. .\" generated by cd2nroff 0.1 from CURLOPT_COOKIE.md
  2. .TH CURLOPT_COOKIE 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_COOKIE \- HTTP Cookie header
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIE, char *cookie);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a pointer to a null\-terminated string as parameter. It is used to set one
  12. or more cookies in the HTTP request. The format of the string should be
  13. NAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookie
  14. should contain.
  15. To set multiple cookies, set them all using a single option concatenated like
  16. this: "name1=content1; name2=content2;" etc.
  17. This option sets the cookie header explicitly in the outgoing request(s). If
  18. multiple requests are done due to authentication, followed redirections or
  19. similar, they all get this cookie passed on.
  20. The cookies set by this option are separate from the internal cookie storage
  21. held by the cookie engine and they are not be modified by it. If you enable
  22. the cookie engine and either you have imported a cookie of the same name
  23. (e.g. \(aqfoo\(aq) or the server has set one, it has no effect on the cookies you
  24. set here. A request to the server sends both the \(aqfoo\(aq held by the cookie
  25. engine and the \(aqfoo\(aq held by this option. To set a cookie that is instead held
  26. by the cookie engine and can be modified by the server use
  27. \fICURLOPT_COOKIELIST(3)\fP.
  28. Using this option multiple times makes the last set string override the
  29. previous ones.
  30. This option does not enable the cookie engine. Use \fICURLOPT_COOKIEFILE(3)\fP
  31. or \fICURLOPT_COOKIEJAR(3)\fP to enable parsing and sending cookies
  32. automatically.
  33. The application does not have to keep the string around after setting this
  34. option.
  35. If libcurl is built with PSL (\fIPublic Suffix List\fP) support, it detects and
  36. discards cookies that are specified for such suffix domains that should not be
  37. allowed to have cookies. If libcurl is \fInot\fP built with PSL support, it has no
  38. ability to stop super cookies. PSL support is identified by the
  39. \fBCURL_VERSION_PSL\fP feature bit returned by \fIcurl_version_info(3)\fP.
  40. .SH DEFAULT
  41. NULL, no cookies
  42. .SH PROTOCOLS
  43. This functionality affects http only
  44. .SH EXAMPLE
  45. .nf
  46. int main(void)
  47. {
  48. CURL *curl = curl_easy_init();
  49. if(curl) {
  50. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  51. curl_easy_setopt(curl, CURLOPT_COOKIE, "tool=curl; fun=yes;");
  52. curl_easy_perform(curl);
  53. }
  54. }
  55. .fi
  56. .SH AVAILABILITY
  57. Added in curl 7.1
  58. .SH RETURN VALUE
  59. Returns CURLE_OK if HTTP is enabled, CURLE_UNKNOWN_OPTION if not, or
  60. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  61. .SH SEE ALSO
  62. .BR CURLINFO_COOKIELIST (3),
  63. .BR CURLOPT_COOKIEFILE (3),
  64. .BR CURLOPT_COOKIEJAR (3),
  65. .BR CURLOPT_COOKIELIST (3),
  66. .BR CURLOPT_HTTPHEADER (3)