【问题标题】:How to use the Poco C++ HTTPSessionFactory如何使用 Poco C++ HTTPSessionFactory
【发布时间】:2011-09-16 00:26:53
【问题描述】:

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

【问题讨论】:

  • 文档是否缺少示例?
  • 很遗憾,有几个优秀的 HTTPClientSession 示例,但没有一个使用 HTTPSessionFactory。

标签: c++ httpsession poco-libraries


【解决方案1】:

您需要注册“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);

【讨论】:

    猜你喜欢
    • 2012-12-07
    • 2012-06-08
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多