CURLOPT_COOKIEFILE.3 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. .\" generated by cd2nroff 0.1 from CURLOPT_COOKIEFILE.md
  2. .TH CURLOPT_COOKIEFILE 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_COOKIEFILE \- filename to read cookies from
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEFILE, char *filename);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a pointer to a null\-terminated string as parameter. It should point to
  12. the filename of your file holding cookie data to read. The cookie data can be
  13. in either the old Netscape / Mozilla cookie data format or just regular HTTP
  14. headers (Set\-Cookie style) dumped to a file.
  15. It also enables the cookie engine, making libcurl parse and send cookies on
  16. subsequent requests with this handle.
  17. By passing the empty string ("") to this option, you enable the cookie engine
  18. without reading any initial cookies. If you tell libcurl the filename is "\-"
  19. (just a single minus sign), libcurl instead reads from stdin.
  20. This option only \fBreads\fP cookies. To make libcurl write cookies to file,
  21. see \fICURLOPT_COOKIEJAR(3)\fP.
  22. If you read cookies from a plain HTTP headers file and it does not specify a
  23. domain in the Set\-Cookie line, then the cookie is not sent since the cookie
  24. domain cannot match the target URL\(aqs. To address this, set a domain in
  25. Set\-Cookie line (doing that includes subdomains) or preferably: use the
  26. Netscape format.
  27. If you use this option multiple times, you add more files to read cookies
  28. from.
  29. The application does not have to keep the string around after setting this
  30. option.
  31. Setting this option to NULL (since 7.77.0) explicitly disables the cookie
  32. engine and clears the list of files to read cookies from.
  33. .SH SECURITY
  34. This document previously mentioned how specifying a non\-existing file can also
  35. enable the cookie engine. While true, we strongly advise against using that
  36. method as it is too hard to be sure that files that stay that way in the long
  37. run.
  38. .SH DEFAULT
  39. NULL
  40. .SH PROTOCOLS
  41. This functionality affects http only
  42. .SH EXAMPLE
  43. .nf
  44. int main(void)
  45. {
  46. CURL *curl = curl_easy_init();
  47. if(curl) {
  48. CURLcode res;
  49. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
  50. /* get cookies from an existing file */
  51. curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
  52. res = curl_easy_perform(curl);
  53. curl_easy_cleanup(curl);
  54. }
  55. }
  56. .fi
  57. .SH Cookie file format
  58. The cookie file format and general cookie concepts in curl are described
  59. online here: https://curl.se/docs/http\-cookies.html
  60. .SH AVAILABILITY
  61. Added in curl 7.1
  62. .SH RETURN VALUE
  63. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  64. .SH SEE ALSO
  65. .BR CURLOPT_COOKIE (3),
  66. .BR CURLOPT_COOKIEJAR (3),
  67. .BR CURLOPT_COOKIESESSION (3)