c++ - 来自 curl++ 的 POST 数据不发送

标签 c++ curl curlpp

我一直在尝试将 curlpp 中的数据发布到网络脚本中,但它似乎不起作用。在 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; 

我在这里做错了什么吗?

最佳答案

对于客户端到服务器的上传,standard指定内容类型将是 application/x-www-form-urlencodedmultipart/form-data 之一。因为您的 Web 服务器和/或 PHP 遵循标准,所以您应该将您的内容类型更改为 application/x-www-form-urlencoded

关于c++ - 来自 curl++ 的 POST 数据不发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6826717/

相关文章:

c++ - 如何使用 CURLPP 库通过 C/C++ 代码检查网站是 http 还是 https?

c++ - 在Kubuntu上使用code::blocks未定义对curlpp的引用

C++:每次我通过fstream读入时,最后都会多出一个字符

c++ - 指向根的二叉树指针需要被引用和取消引用。为什么?

c++ - Qt + OpenCV灰度错误

php - 使用 cURL 的 Bug 订阅 instagram API

cURL SSL 无法在 Xampp 上获取本地颁发者证书

c++ - 将 char 数组吐出到一系列 int 和 float 中

php - 在 PHP 中使用 CURL 下载后 MD5 校验和不正确 - file_get_contents 工作正常

c++ - 使用 curlpp 发布和接收 JSON 负载