Poco::Net::HTTPRequest 无法解析主机

Poco::Net::HTTPRequest is unable to resolve host

我在 poco c++ 库中编写了一个代码,它应该向服务器发送请求以获取一些数据。 运行ning 来自 docker 容器。而且我收到“主机名未解析”错误。示例代码如下

//initialize session
Poco::SharedPtr<InvalidCertificateHandler> ptrCert = new AcceptCertificateHandler(false);
_ptrContext = new Context(Context::TLSV1_2_CLIENT_USE, "", "", "", Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");

_ptrContext->enableSessionCache(true);
// Disable SSL versions 2 & 3 and TLS versions 1.0 & 1.1
_ptrContext->disableProtocols(Poco::Net::Context::PROTO_SSLV2 | Poco::Net::Context::PROTO_SSLV3 | Poco::Net::Context::PROTO_TLSV1 | Poco::Net::Context::PROTO_TLSV1_1);

SSLManager::instance().initializeClient(0, ptrCert, _ptrContext);
_httpsession_secure = new HTTPSClientSession(_hostname, _port);

//build request
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, uri, Poco::Net::HTTPMessage::HTTP_1_1);

req.setContentLength(http_body.length());
req.setContentType("application/x-www-form-urlencoded");

// Send request
std::ostream &os = _httpsession_secure->sendRequest(req);
os << http_body;

// Wait for response
Poco::Net::HTTPResponse res;
std::istream &rs = _httpsession_secure->receiveResponse(res);

我有 运行 一个 curl 命令作为 docker 容器中的 CMD 条目,该命令正在正确执行并给出结果。这意味着可以在容器内访问主机。当我在容器内执行代码时,它失败了。所以我肯定在代码中遗漏了一些东西。请指导。

根据您在评论中对我的问题的回答,您正在使用:

_httpsession_secure = new HTTPSClientSession(_hostname, _port);

其中 _hostname 的形式为 https://somehost.somedomain.

这是错误的,你不能在那里传递一个URI,你只需要传递域名。

_hostname = "somehost.somedomain";
_httpsession_secure = new HTTPSClientSession(_hostname, _port);