我正在尝试使用 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/