c++ - Libcurl - cookie 身份验证

标签 c++ libcurl

我想在将 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/

相关文章:

c++ - C++中函数指针的模板typedef

c++ - 套接字上的数据类型信息;动态初始化?

xcode - 在 OS X 10.11 上构建静态 libcurl.a,但找不到 libcurl.a

C代码: cURL POST

c# - 来自 C# 的服务器名称指示

ios - iOS 上的 libcurl + cookie

c++ - 在 C++ 中追加到 Char 数组的末尾

c++ - vector (具有 vector 的结构)

C++初始化: order of const global vs static class member

c - libcurl 从 HTTP 请求检索响应