我一直在尝试将 curlpp 中的数据发布到 Web 脚本,但它似乎不起作用。在 PHP 端,我只需运行 var_dump($_POST); 打印收到的所有内容。$_POST 全局变量在执行时显示为空。
我的 C++ 代码如下:
std::stringstream out;
std::stringstream ss;
ss << "127.0.0.1/online.php";
try
{
curlpp::Cleanup clean;
curlpp::Easy request;
curlpp::options::WriteStream ws(&out);
request.setOpt(ws);
request.setOpt<curlpp::options::Url>(ss.str());
request.setOpt(new curlpp::options::Verbose(true));
std::list<std::string> header;
header.push_back("Content-Type: application/octet-stream");
request.setOpt(new curlpp::options::HttpHeader(header));
std::string test = "abcd=abcd";
request.setOpt(new curlpp::options::PostFields(test));
request.setOpt(new curlpp::options::PostFieldSize(test.length()));
request.perform();
}
catch(curlpp::RuntimeError& e)
{
ss.str("");
ss << "Error making request of type " << op << ": " << e.what();
PrintError(ss.str());
return "";
}
std::cout << out.str() << std::endl;
我在这里做任何明显错误的事情吗?