tags:

views:

25

answers:

2

I am trying to build a C++ app to access a XML resource. Using http the code works fine, from what I can tell from the docs, all I need to do to for the https to work is to make sure ssl is install (yes the dev edition is installed), and change the StreamFactory to HTTPSStreamFactory.

Here is the code that works :

Poco::Net::HTTPStreamFactory::registerFactory();
Poco::URI uri(argv[1]);

std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri));
std::string str;      
StreamCopier::copyToString(*pStr.get(), str);

Here is the code that fails Poco::Net::HTTPSStreamFactory::registerFactory(); Poco::URI uri(argv[1]);

std::auto_ptr<std::istream> pStr(Poco::URIStreamOpener::defaultOpener().open(uri));
std::string str;      
StreamCopier::copyToString(*pStr.get(), str);

When I make a request w/ HTTPSStreamFactory this is the error message I get :

NULL pointer: _pInstance [in file "/home/chpick/poco-1.3.6p2/Util/include/Poco/Util/Application.h", line 422]

I have attached the Application.h

inline Application& Application::instance()
{
    poco_check_ptr (_pInstance);
    return *_pInstance;
}

Any help would be great. Thanks

+1  A: 

Check the documentation for something along the lines of check certificate. You see, SSL works by the server and client exchanging certificates, and in every library I've used that does SSL, the developer has to create a function or in some other way validate the certificate the server sent; which usually means the developer just accepts anything without checking because most people don't really care about that. You program might be seg-faulting because that code is being called, and nothing is being returned, so a null is being dereferenced, or something like that.

Gianni
Ok, thanks, I will check that out. I saw something about that for client side (accept all) will check it out. thanks
Chrispix
A: 

I ended up going about it a different way : Here is what I did.

    const Poco::URI uri(xmlParams.restURI);
    std::string path(argv[1]);
    const Poco::Net::Context::Ptr context = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context );
    Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, argv[1] );
    req.setKeepAlive(false);

  std::string strToSend = "/";
    session.sendRequest(req) << strToSend;
    Poco::Net::HTTPResponse res;
    std::istream& rs = session.receiveResponse(res);    // typedef std::istream XMLCharInputStream;

    std::string str;    
    StreamCopier::copyToString(rs, str);

    std::istringstream istr(str);
    InputSource source(istr);
    parser.parse(&source);
Chrispix