Reputation: 7769
I am using the POCO::Net::HTTPClientSession
class to connect to the web server on IoT devices. I now need to support HTTPS to the device, but whether its HTTP or HTTPS is a configurable parameter in the device profile that may change at runtime.
I can connect just fine on HTTPS using the HTTPSClientSession
class, and I can obviously connect on HTTP using the HTTPClientSession
class. But I rather not use two objects for the two protocols. It seems I should be able to use the HTTPSClientSession
object for both, since class HTTPSClientSession
is a subclass of HTTPClientSession
.
When I attempt to use an HTTPSClientSession
object to talk to a plain HTTP server listening on port 80, The HTTPClientSession::sendRequest
method throws exception Poco::Net::NetException
with the message:
140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Is it appropriate to be trying to use the HTTPSClientSession
object for HTTP? If so, what do I need to do?
Upvotes: 0
Views: 828
Reputation: 105
I think you can't use HTTPSClientSession
for HTTP communication. But you can make use of the fact that HTTPSClientSession
is a subclass of HTTPClientSession
:
std::shared_ptr<HTTPClientSession> session;
if(https) {
session.reset(new HTTPSClientSession());
}
else {
session.reset(new HTTPClientSession());
}
Upvotes: 1