C++ 使用cpprest上传文件,给出501错误作为响应
我正在使用链接中的代码上传文件,并得到501未实现的响应C++ 使用cpprest上传文件,给出501错误作为响应,c++,casablanca,cpprest-sdk,C++,Casablanca,Cpprest Sdk,我正在使用链接中的代码上传文件,并得到501未实现的响应 // Upload a file to an HTTP server. pplx::task<void> UploadFileToHttpServerAsync() { using concurrency::streams::file_stream; using concurrency::streams::basic_istream; retur
// 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();
});
}
});
}
//将文件上载到HTTP服务器。
pplx::任务上载文件到HttpServerAsync()
{
使用concurrency::streams::file\u stream;
使用concurrency::streams::basic_istream;
返回文件\u stream::open\u istream(L“myfile.txt”)。然后([](pplx::task previousTask)
{
尝试
{
auto fileStream=previousTask.get();
//以文件流作为主体发出HTTP请求。
http_客户端(L)http://www.fourthcoffee.com");
返回client.request(methods::PUT,L“myfile”,fileStream)。然后([fileStream](pplx::task previousTask)
{
fileStream.close();
标准:WOSS;
尝试
{
自动响应=previousTask.get();
ss“www.fourthcoffee.com”只是一个例子-它重定向到www.microsoft.com。您需要一个接受上载的服务器。在我的代码中,我更改了URI。它是一个应该支持PUT上载的服务器吗?是的,它支持。