CURLOPT_COOKIEJAR.3 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. .\" generated by cd2nroff 0.1 from CURLOPT_COOKIEJAR.md
  2. .TH CURLOPT_COOKIEJAR 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_COOKIEJAR \- filename to store cookies to
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEJAR, char *filename);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a \fIfilename\fP as a char *, null\-terminated. This makes libcurl write
  12. all internally known cookies to the specified file when
  13. \fIcurl_easy_cleanup(3)\fP is called. If no cookies are kept in memory at that
  14. time, no file is created. Specify "\-" as filename to instead have the cookies
  15. written to stdout. Using this option also enables cookies for this session, so
  16. if you for example follow a redirect it makes matching cookies get sent
  17. accordingly.
  18. Note that libcurl does not read any cookies from the cookie jar specified with
  19. this option. To read cookies from a file, use \fICURLOPT_COOKIEFILE(3)\fP.
  20. If the cookie jar file cannot be created or written to (when the
  21. \fIcurl_easy_cleanup(3)\fP is called), libcurl does not and cannot report an
  22. error for this. Using \fICURLOPT_VERBOSE(3)\fP or
  23. \fICURLOPT_DEBUGFUNCTION(3)\fP displays a warning, but that is the only
  24. visible feedback you get about this possibly lethal situation.
  25. Cookies are imported in the Set\-Cookie format without a domain name are not
  26. exported by this option.
  27. The application does not have to keep the string around after setting this
  28. option.
  29. .SH DEFAULT
  30. NULL
  31. .SH PROTOCOLS
  32. This functionality affects http only
  33. .SH EXAMPLE
  34. .nf
  35. int main(void)
  36. {
  37. CURL *curl = curl_easy_init();
  38. if(curl) {
  39. CURLcode res;
  40. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
  41. /* export cookies to this file when closing the handle */
  42. curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt");
  43. res = curl_easy_perform(curl);
  44. /* close the handle, write the cookies! */
  45. curl_easy_cleanup(curl);
  46. }
  47. }
  48. .fi
  49. .SH AVAILABILITY
  50. Added in curl 7.9
  51. .SH RETURN VALUE
  52. Returns CURLE_OK if HTTP is supported, CURLE_UNKNOWN_OPTION if not, or
  53. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  54. .SH SEE ALSO
  55. .BR CURLOPT_COOKIE (3),
  56. .BR CURLOPT_COOKIEFILE (3),
  57. .BR CURLOPT_COOKIELIST (3)