我想在将 cookie 与 Libcurl 一起使用时避免使用文件系统...这可能吗?似乎文档和示例都需要使用从文件中写入和读取 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;");
关于c++ - Libcurl - cookie 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31663872/