C++14 cURLcpp提交表单
C++14 cURLcpp Submitting a form
我正在尝试使用cURLcpp(而不是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:UsersCzarekClionProjectsLearningmain.cpp: In function 'int main(int, const char**)':
C:UsersCzarekClionProjectsLearningmain.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
类没有任何接受curl_form
的add()
版本。看起来只有add()变体用于CURLOption。
我想明白了。事实证明,网站上的教程有点错误。easy.add<OPT>(value)
函数接受curl_httpost变量。要从curl_form
获得它,必须执行form.get()
。但要将其传递给easy.add()
函数,必须使用const_cast
移除常量。我相信这只是图书馆里的一个bug。
相关文章:
- GTK 最大化表单 C++
- win 表单应用程序字符串^ 到 int
- 结构化绑定初始值设定项表单 { 赋值表达式 } 对于 clang 上的数组类型失败
- 可以在JSON文件的帮助下在Qt中创建UI表单
- 表单未显示在凭据提供程序中
- 表单显示对话框函数错误,并且不执行下面的语句
- 如何从 winapi 中的编辑表单获取文本?
- 在 cout 中将线条表单文件与自定义文本组合时出现问题
- 从 dll 调用 opencv 垫到 Windows 表单,图像出现故障
- 如何在不使用任何数据库的情况下制作动态注册表单?
- 家庭作业帮助 - 检查表单按钮上的数据
- C++ 在给定像素数据数组的表单上绘制矩形
- 复制初始化表单 '= {}'
- 如何创建第二个 QT .ui 表单
- 如何将变量从一个表单传递到另一个表单
- 使用CPP手动构建POST请求,并使用它提交php表单
- POCO C 简单表单提交样本不起作用
- C++14 cURLcpp提交表单
- 如何执行表单提交
- 编译在在线 HTML 表单上提交的代码并使用 GCC 进行处理的过程