2011-06-16 73 views
4

如何設置HTTPSessionFactory同時處理HTTP和HTTPS的最簡單方法?我知道我需要使用HTTPSessionInstantiators,但我真的可以使用一個簡短而好看的例子。謝謝。如何使用Poco C++ HTTPSessionFactory

+0

是否文檔缺乏的例子嗎? – 2011-06-16 05:58:13

+0

不幸的是,有幾個很好的HTTPClientSession示例,但沒有使用HTTPSessionFactory。 – 2011-06-16 12:13:54

回答

3

您需要註冊'http'和'https'協議。

以及處理的「https」,你還需要有證書和上下文配置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);