【问题标题】:POCO C++ library: connect to server with HTTPS or HTTPPOCO C++ 库:使用 HTTPS 或 HTTP 连接到服务器
【发布时间】:2019-06-24 16:39:43
【问题描述】:

我正在使用POCO::Net::HTTPClientSession 类连接到物联网设备上的网络服务器。我现在需要支持设备的 HTTPS,但它的 HTTP 或 HTTPS 是设备配置文件中的可配置参数,可能会在运行时更改。

我可以使用 HTTPSClientSession 类在 HTTPS 上很好地连接,我显然可以使用 HTTPClientSession 类在 HTTP 上连接。但我宁愿不为这两个协议使用两个对象。看来我应该可以同时使用HTTPSClientSession 对象,因为HTTPSClientSession 类是HTTPClientSession 的子类。

当我尝试使用 HTTPSClientSession 对象与侦听端口 80 的普通 HTTP 服务器通信时,HTTPClientSession::sendRequest 方法抛出异常 Poco::Net::NetException 并显示以下消息:

140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

尝试将HTTPSClientSession 对象用于HTTP 是否合适?如果是这样,我需要做什么?

【问题讨论】:

    标签: poco-libraries


    【解决方案1】:

    我认为您不能使用 HTTPSClientSession 进行 HTTP 通信。但是您可以利用HTTPSClientSessionHTTPClientSession 的子类这一事实:

    std::shared_ptr<HTTPClientSession> session;
    if(https) {
      session.reset(new HTTPSClientSession());
    }
    else {
      session.reset(new HTTPClientSession());
    }
    

    【讨论】:

      猜你喜欢
      • 2014-04-06
      • 1970-01-01
      • 2018-12-11
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-09
      相关资源
      最近更新 更多