0

我正在使用链接https://msdn.microsoft.com/en-us/library/jj950081.aspx中的代码上传文件 anf 得到响应,因为 501 未实现。

// Upload a file to an HTTP server.
    pplx::task<void> UploadFileToHttpServerAsync()
        {
            using concurrency::streams::file_stream;
            using concurrency::streams::basic_istream;

    return file_stream<unsigned char>::open_istream(L"myfile.txt").then([](pplx::task<basic_istream<unsigned char>> previousTask)
    {
        try
        {
            auto fileStream = previousTask.get();

            // Make HTTP request with the file stream as the body.
            http_client client(L"http://www.fourthcoffee.com");
            return client.request(methods::PUT, L"myfile", fileStream).then([fileStream](pplx::task<http_response> previousTask)
            {
                fileStream.close();

                std::wostringstream ss;
                try
                {
                    auto response = previousTask.get();
                    ss << L"Server returned returned status code " << response.status_code() << L"." << std::endl;
                }

                std::wcout << ss.str();
            });
        }
    });
}
4

0 回答 0