C ++ - Http PUT文件上传无法在服务器CppRest上运行

时间:2017-05-09 10:26:52

标签: php c++ http localhost cpprest-sdk

我正在尝试通过以下代码(使用cpprest库)将图片上传到我服务器上的其他API:

int uploadActiveUserImage(std::string *fileName)
{
auto fileStream = std::make_shared<istream>();
// Open stream to output file.
      pplx::task<void> requestTask = fstream::open_istream("activeUser.png").then([=](istream frame)
      {
         *fileStream = frame;
         // Create http_client to send the request.
         auto client = http_client{U(".....website..../api/activeUser/image")};
         //auto client = http_client{U("http://localhost/smartmirrorAPI/smartmirrorAPI/api/activeUser/image")};
        // Build request URI and start the request.
        auto query = uri_builder()
          .to_string();

        return client.request(methods::PUT, query, *fileStream);

})

此代码适用于将图片发送到microsoft faces api以及发送到localhost但不发送到我的服务器时。我可以使用chrome上的邮递员扩展将图片发送到我的api(在我的服务器上),这样就没有文件权限问题。

这是我在服务器上的api代码的snippit,它处理请求。

case 'PUT':
        $data = file_get_contents("php://input");
        if (is_null($data)) {
            header('HTTP/1.1 400 Bad Request');
            header('Content-Type: application/json');
            var_dump($data);
            return;
        }
        $result = file_put_contents("activeUser.png", $data); //Where to save the image on your server
        //var_dump($data);
        echo($result);
发送到服务器上的api时,

$ data是一个空字符串。

请帮帮忙,我一直在找几个小时。

谢谢你,Robbert

0 个答案:

没有答案