Question

I have finally built Poco NetSSL, but already the first example doesn't work. The following snippet throws an exception and Debugger.h gets opened in my IDE (Visual Studio 2012).

#include <Poco/Net/HTTPSClientSession.h>

int main()
{
    Poco::Net::HTTPSClientSession clientSession;
}

This is the output:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NULL pointer: _pInstance [in file "c:\users\domenic\desktop\poco-1.4.6p1-all\util\include\poco\util\application.h", line 446]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The following code just works perfectly...

#include <Poco/Net/HTTPClientSession.h>

int main()
{
    Poco::Net::HTTPClientSession clientSession;
}

I suppose it has something to do with OpenSSL. Hopefully someone can help me, I really want to start my project. :(

Was it helpful?

Solution

If you're using the default constructor of Poco::Net::HTTPSClientSession (or any other constructor that does not take a Poco::Net::Context::Ptr), you'll need to have an instance of Poco::Util::Application, as well as a configuration file containing the SSL/TLS configuration in order to create a default Context object and initialize the Poco::Net::SSLManager, or alternatively, initialize the default Context and SSLManager yourself.

Initializing the default Context and SSLManager involves creating a certificate handler, creating a default Context object and initializing the SSLManager. See the Mail and download samples for how this is done. Typically, the code to do this looks like this:

Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> pCert = 
    new Poco::Net::ConsoleCertificateHandler(false); 
Poco::Net::Context::Ptr pContext = 
    new Poco::Net::Context(
        Poco::Net::Context::CLIENT_USE, 
        "", 
        "", 
        "rootcert.pem", 
        Poco::Net::Context::VERIFY_RELAXED, 
        9, 
        false, 
        "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
SSLManager::instance().initializeClient(0, pCert, pContext);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top