CURLOPT_COOKIELIST.3 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_COOKIELIST 3 "19 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_COOKIELIST \- add to or manipulate cookies held in memory
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIELIST,
  30. char *cookie);
  31. .SH DESCRIPTION
  32. Pass a char * to a \fIcookie\fP string.
  33. Such a cookie can be either a single line in Netscape / Mozilla format or just
  34. regular HTTP-style header (Set-Cookie: ...) format. This will also enable the
  35. cookie engine. This adds that single cookie to the internal cookie store.
  36. Exercise caution if you are using this option and multiple transfers may occur.
  37. If you use the Set-Cookie format and do not specify a domain then the cookie is
  38. sent for any domain (even after redirects are followed) and cannot be modified
  39. by a server-set cookie. If a server sets a cookie of the same name (or maybe
  40. you have imported one) then both will be sent on a future transfer to that
  41. server, likely not what you intended. To address these issues set a domain in
  42. Set-Cookie (doing that will include sub-domains) or use the Netscape format as
  43. shown in EXAMPLE.
  44. Additionally, there are commands available that perform actions if you pass in
  45. these exact strings:
  46. .IP ALL
  47. erases all cookies held in memory
  48. .IP SESS
  49. erases all session cookies held in memory
  50. .IP FLUSH
  51. writes all known cookies to the file specified by \fICURLOPT_COOKIEJAR(3)\fP
  52. .IP RELOAD
  53. loads all cookies from the files specified by \fICURLOPT_COOKIEFILE(3)\fP
  54. .SH DEFAULT
  55. NULL
  56. .SH PROTOCOLS
  57. HTTP
  58. .SH EXAMPLE
  59. .nf
  60. /* This example shows an inline import of a cookie in Netscape format.
  61. You can set the cookie as HttpOnly to prevent XSS attacks by prepending
  62. #HttpOnly_ to the hostname. That may be useful if the cookie will later
  63. be imported by a browser.
  64. */
  65. #define SEP "\\t" /* Tab separates the fields */
  66. char *my_cookie =
  67. "example.com" /* Hostname */
  68. SEP "FALSE" /* Include subdomains */
  69. SEP "/" /* Path */
  70. SEP "FALSE" /* Secure */
  71. SEP "0" /* Expiry in epoch time format. 0 == Session */
  72. SEP "foo" /* Name */
  73. SEP "bar"; /* Value */
  74. /* my_cookie is imported immediately via CURLOPT_COOKIELIST.
  75. */
  76. curl_easy_setopt(curl, CURLOPT_COOKIELIST, my_cookie);
  77. /* The list of cookies in cookies.txt will not be imported until right
  78. before a transfer is performed. Cookies in the list that have the same
  79. hostname, path and name as in my_cookie are skipped. That is because
  80. libcurl has already imported my_cookie and it's considered a "live"
  81. cookie. A live cookie will not be replaced by one read from a file.
  82. */
  83. curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt"); /* import */
  84. /* Cookies are exported after curl_easy_cleanup is called. The server
  85. may have added, deleted or modified cookies by then. The cookies that
  86. were skipped on import are not exported.
  87. */
  88. curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt"); /* export */
  89. curl_easy_perform(curl); /* cookies imported from cookies.txt */
  90. curl_easy_cleanup(curl); /* cookies exported to cookies.txt */
  91. .fi
  92. .SH "Cookie file format"
  93. The cookie file format and general cookie concepts in curl are described in
  94. the HTTP-COOKIES.md file, also hosted online here:
  95. https://curl.se/docs/http-cookies.html
  96. .SH AVAILABILITY
  97. ALL was added in 7.14.1
  98. SESS was added in 7.15.4
  99. FLUSH was added in 7.17.1
  100. RELOAD was added in 7.39.0
  101. .SH RETURN VALUE
  102. Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
  103. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  104. .SH "SEE ALSO"
  105. .BR CURLOPT_COOKIEFILE "(3), " CURLOPT_COOKIEJAR "(3), " CURLOPT_COOKIE "(3), "
  106. .BR CURLINFO_COOKIELIST "(3), "