如何使用Poco C ++ HTTPSessionFactory

时间:2011-06-16 02:01:20

标签: c++ httpsession poco-libraries

设置HTTPSessionFactory以处理HTTP和HTTPS的最佳,最简单的方法是什么?我知道我需要使用HTTPSessionInstantiators,但我真的可以使用一个简短而甜蜜的例子。感谢。

1 个答案:

答案 0 :(得分:3)

您需要注册“http”和“https”协议。

为了处理'https',您还需要使用cert和context配置您的SSLManager,这是一段示例代码:

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