【问题标题】:HTTPS Get SSL Excpetion with Poco C++: OSM NominatimHTTPS 使用 Poco C++ 获取 SSL 异常:OSM Nominatim
【发布时间】:2018-05-31 01:37:41
【问题描述】:

我正在尝试向 OpenStreetMaps Nominatim 地理编码服务器发出 HTTPS Get 请求,但它给出了 SSL Excpetion,我终其一生都无法弄清楚。

一个典型的请求 URL 是这样的: https://nominatim.openstreetmap.org/reverse?format=json&lat=37.325460&lon=-121.777310 在我的浏览器中工作。 这是我的代码:

std::string httpsGet(const std::string& hostname, int port, const  std::string& path,  const std::string& query)
{
   Poco::Net::initializeSSL();
   Poco::Net::SSLManager::InvalidCertificateHandlerPtr ptrHandler ( new    Poco::Net::AcceptCertificateHandler(false) );
   Poco::Net::Context::Ptr ptrContext ( new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH") );
   Poco::Net::SSLManager::instance().initializeClient(0, ptrHandler, ptrContext);

   try {

     URI uri(hostname); // https://nominatim.openstreetmap.org
     uri.setPort(port); // 80
     HTTPSClientSession session(uri.getHost(),uri.getPort());


     uri.setPath(path); // reverse/
     uri.setQuery(query); // format=json&lat=37.325460&lon=-121.777310 
     std::string _path(uri.getPathAndQuery());

     // send request
      HTTPRequest req(HTTPRequest::HTTP_GET, _path, HTTPMessage::HTTP_1_1);
     req.set("user-agent", "[myemail]");
     session.sendRequest(req);

      HTTPResponse res;        
      std::istream &is = session.receiveResponse(res);
      std::stringstream ss;
      StreamCopier::copyStream(is, ss);
      return ss.str(); 
   } catch (std::exception &ex) {
      std::cout << "HTTP GET error [" << ex.what() << "]"  << std::endl;
      return "";
   }
}

但我收到以下错误: “SSL 异常”

SSL 代码已从作为答案给出的其他 StackOverlfow 帖子中复制,但它似乎在这里不起作用?

【问题讨论】:

    标签: ssl https openstreetmap poco nominatim


    【解决方案1】:

    我一发布就意识到我的失败。 我使用 HTTP 端口 80,对于 SSL HTTPS,您需要端口 443(通常)。

    我一改就没事了。其他 SO 帖子没有指出过度尝试的工程师切换 HTTP 代码的明显之处,所以我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 2016-06-29
      • 2014-09-06
      • 2015-09-25
      • 2011-07-19
      相关资源
      最近更新 更多