开发者

How to use the Poco C++ HTTPSessionFactory

开发者 https://www.devze.com 2023-03-13 12:53 出处:网络
How is the best, simplest way to set up t开发者_StackOverflow社区he HTTPSessionFactory to handle both HTTP and HTTPS? I know that I need to use HTTPSessionInstantiators, but I could really use a short

How is the best, simplest way to set up t开发者_StackOverflow社区he 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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消