Libcurl - cookie authentication

Libcurl - cookie authentication

本文关键字:authentication cookie Libcurl      更新时间:2023-10-16

我想在Libcurl使用cookie时避免使用文件系统…这可能吗?似乎文档和示例都需要使用从文件中写入和读取cookie…也许我错了。

到目前为止,我做的是这样的:

curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfield);
curl_easy_setopt(curl, CURL_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
//writes the cookie to file sent from server
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, COOKIE_FILENAME);
curl_easy_perform(curl);
curl_easy_cleanup(curl);

http://curl.haxx.se/libcurl/c/cookie_interface.html在不使用文件系统的情况下也可以打印和编辑cookie。

我自己用那个例子来做整个cookie修改的事情。

也很有用,但不是在例子中:

 curl_easy_setopt(curl, CURLOPT_COOKIE, "name=xxx; name2=xxx;");