How is the best, simplest way to set up the HTTPSessionFactory to handle both HTTP and HTTPS? I know that I need to use HTTPSessionInstantiators, but I could really use a short and sweet example. Thanks.
Asked
Active
Viewed 1,721 times
4
-
Does the documentation lack an example? – Cheers and hth. - Alf Jun 16 '11 at 05:58
-
unfortunately yes, there are several excellent HTTPClientSession samples, but none that use HTTPSessionFactory. – Thoughtful Dragon Jun 16 '11 at 12:13
1 Answers
3
You need to register the 'http' and 'https' protocols.
And for handling 'https', you also need to configure your SSLManager with cert and context, here is a piece of example code:
//register http and https
HTTPSessionFactory::defaultFactory().registerProtocol("http", new HTTPSessionInstantiator);
HTTPSessionFactory::defaultFactory().registerProtocol("https", new HTTPSSessionInstantiator);
//prepare for SSLManager
SharedPtr ptrCert = new AcceptCertificateHandler(false);
const Poco::Net::Context::Ptr context = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
SSLManager::instance().initializeClient(0, ptrCert, context);
// now you have the HTTP(S)ClientSession
HTTPClientSession *session = HTTPSessionFactory::defaultFactory().createClientSession(uri);

clsung
- 1,672
- 19
- 21