我使用下面的代码作为示例来使用VC ++中的REST服务。我收到一条错误,指出“无法建立与服务器的连接”。我的系统的IIs版本是IIS 6.0。请让我知道可能是什么问题。提前谢谢。
#include "stdafx.h"
#include "http_client.h"
#include "filestream.h"
#include "iostream"
#include "sstream"
#include "conio.h"
#include "Windows.h"
using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;
int _tmain(int argc, _TCHAR* argv[])
{
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.bing.com/"));
uri_builder builder(U("/search"));
builder.append_query(U("q"), U("Casablanca CodePlex"));
return client.request(methods::GET, builder.to_string());
// Build request URI and start the request.
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception &e)
{
printf("Error exception:%s\n", e.what());
}
Sleep(5000);
return 0;
}