????????????????????????http??--C++ REST SDK??http://casablanca.codeplex.com/??????????????????Casablanca???и???????????????????????????????????????ɡ???REST SDK????????????????????rest API?????REST???????Ь??????????????????REST API?????????application/x-www-form-urlencoded??application/json??application/octet-stream???????????REST API??????????json???????????????Casablanca????c++11????????????PPL??asio???????????????web socket?????????????????????????????????????

 

#include <cppresthttp_client.h>
#include <cpprestfilestream.h>
using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency;
void TestRequest()
{
auto fileStream = std::make_shared<concurrency::streams::ostream>();
pplx::task<void> requestTask = concurrency::streams::fstream::open_ostream(U("result.html")).then([=](concurrency::streams::ostream
outFile){
*fileStream = outFile;
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());
})
.then([=](http_response response)
{
return response.body().read_to_end(fileStream->streambuf());
}).then([=](size_t len){
return fileStream->close();
});
try
{
requestTask.wait();
}
catch (const std::exception& e)
{
cout << e.what() << endl;
}
}

?????????????bing.com????“Casablanca CodePlex”????????浽??????????result.html?У??????ppl??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????rest sdk????????????????????wchr_t???????????http?????????????http???????ú????????е?С????^_^??????????????????ppl?÷????Ь?????е???????????????????????£????????????????????????

 

void TestRequest()
{
auto fileStream = std::make_shared<concurrency::streams::ostream>();
concurrency::streams::ostream outFile = concurrency::streams::fstream::open_ostream(U("result11.html")).get();
*fileStream = outFile;
http_client client(L"http://www.bing.com/");
uri_builder builder(L"/search");
builder.append_query(L"q"?? L"Casablanca CodePlex");
http_response response = client.request(methods::GET?? builder.to_string()).get();
response.body().read_to_end(fileStream->streambuf()).get();
fileStream->close().get();
}