C++14 cURLcpp 提交表单

标签 c++ libcurl c++14

我正在尝试使用 cURLcpp (not cURLpp)提交表格。自述文件中有一个如何发送表单请求的示例。这是我的代码:

const std::string authenticityToken = stringMatch.substr(7, stringMatch.length());

curl::curl_form form;
curl::curl_easy easy;
// Forms creation
curl::curl_pair<CURLformoption,std::string> nameForm(CURLFORM_COPYNAME, "username");
curl::curl_pair<CURLformoption,std::string> nameCont(CURLFORM_COPYCONTENTS, "the username");

curl::curl_pair<CURLformoption,std::string> passForm(CURLFORM_COPYNAME, "password");
curl::curl_pair<CURLformoption,std::string> passCont(CURLFORM_COPYCONTENTS, "the password");

curl::curl_pair<CURLformoption,std::string> authForm(CURLFORM_COPYNAME,"authenticityToken");
curl::curl_pair<CURLformoption,std::string> authCont(CURLFORM_COPYCONTENTS, authenticityToken);

try {
    // Form adding
    form.add(nameForm, nameCont);
    form.add(passForm, passCont);
    form.add(authForm, authCont);

    // Add some options to our request
    easy.add<CURLOPT_URL>("https://account.mojang.com/login");
    easy.add<CURLOPT_SSL_VERIFYPEER>(false);
    easy.add<CURLOPT_FOLLOWLOCATION>(1L);
    easy.add<CURLOPT_HTTPPOST>(form);
    // Execute the request.
    easy.perform();
} catch (curl::curl_easy_exception error) {
    // If you want to get the entire error stack we can do:
    curl::curlcpp_traceback errors = error.get_traceback();
    // Otherwise we could print the stack like this:
    error.print_traceback();
    // Note that the printing the stack will erase it
}

编译时出现这个错误:

C:\Users\Czarek\ClionProjects\Learning\main.cpp: In function 'int main(int, const char**)':
C:\Users\Czarek\ClionProjects\Learning\main.cpp:40:40: error: no matching function for call to 'curl::curl_easy::add(curl::curl_form&)'
         easy.add<CURLOPT_HTTPPOST>(form);

现在,我按照 github 上概述的示例进行操作了吗?我做错了什么?

最佳答案

显然 curl_easy 类没有任何版本的 add() 接受 curl_form。看起来它只有 add() 变体适用于 CURLOption。

关于C++14 cURLcpp 提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34535634/

相关文章:

c++ - void foo(T<U>&& param) 中的通用引用

c++ - 处理 linux 上的库依赖

libCurl : curl_easy_setopt in one method and curl_easy_perform in another does not work

c++ - 使用 auto 重载模板函数的解析

c++ - Objective C 和 C++ 中的可变性设计模式

c++ - 无法在 C++ 中创建结构 vector

c++ - Qt LNK2019 基本 Qt5 应用程序错误

c++ - 您应该通过命令行使用 curl 还是包含库?

c++ - 元组 View 的元素类型

c++ - 使用 constexpr 函数的返回值作为另一个函数的参数