I have written a code in poco c library that is supposed to send a request to the server to get some data. The is running from inside a docker container. And I am getting a "hostname not resolved" error. The sample code is as follow
//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);
I have run a curl command as the CMD entry in the docker container, and the command is executing properly and giving the result. so that means the host is accessible inside the container. When I execute the code inside the container, it is failing. So I am surely missing something in the code. Please guide.
CodePudding user response:
As per your answer to a my question in the comments, you are using:
_httpsession_secure = new HTTPSClientSession(_hostname, _port);
where _hostname
is of the form to https://somehost.somedomain
.
This is wrong, you must not pass an URI there, you just have to pass the domain name.
_hostname = "somehost.somedomain";
_httpsession_secure = new HTTPSClientSession(_hostname, _port);