HTTP异常::无法连接到任何解决的端点-CPPRESTSDK
HTTP Exception :: Failed to connect to any resolved endpoint - cpprestsdk
我正在尝试使用 Microsoft的CPPRESTSDK ,但是我遇到了此错误:
http exception ::无法连接到任何已解决的端点代码:: 101
这是我的代码:
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int main(int argc, char* 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/"));
// Build request URI and start the request.
uri_builder builder(U("search"));
builder.append_query(U("q"), U("cpprestsdk github"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%un", 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 (web::http::http_exception &e)
{
printf("HTTP Exception :: %snCode :: %dn", e.what(), e.error_code());
}
catch (const std::exception &e)
{
printf("Error exception:%sn", e.what());
}
return 0;
}
来源:https://github.com/microsoft/cpprestsdk/wiki/getting-started-tutorial
我使用了此
g++ -std=c++11 my_file.cpp -o my_file -lboost_system -lcrypto -lssl -lcpprest
./my_file
构建我的代码。但是我收到的错误代码为101。怎么了?
cpprest 使用 boost asio [1],在您的情况下,这是asio::error::network_unreachable
101。确保您可以访问Internet(例如,尝试使用URL(。
如果您使用代理访问Internet,则需要在http_client
中进行配置:
web::http::client::http_client_config cfg;
cfg.set_proxy(web::web_proxy(U("enter your proxy url here")));
// and passing in the to the client constructor
http_client client(U("http://www.bing.com/"), cfg);
相关文章:
- 运行同一解决方案的另一个项目的项目
- Project Euler问题4的错误解决方案
- Ardunio UNO解决了多个重叠的定时器循环
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 两个文件使用彼此的功能-如何解决
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 在java中解决这段代码时面临循环中的问题
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 难以理解某些人解决IOI问题的源代码
- visual c++,如何获取解决方案目录中的代码
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 节俭并发:未解决的外部问题
- IpOpt拒绝解决不受约束的问题
- 如何解决这个超硬恒星的创造问题
- 循环无限运行C++解决骑士之旅问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- C++Matching Brackets 2解决方案不起作用
- 在 ubuntu3 上C++ goto 定义有什么解决方案吗16.04?
- HTTP异常::无法连接到任何解决的端点-CPPRESTSDK