我一直在尝试将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;
我在这里做了什么非常明显的错误吗?