user1978816
user1978816

Reputation: 822

HTTPS Get SSL Excpetion with Poco C++: OSM Nominatim

I am trying to make an HTTPS Get request to the OpenStreetMaps Nominatim geocoding server, but it is giving a SSL Excpetion and for the life of me I can't figure it out.

A typical request URL is this: https://nominatim.openstreetmap.org/reverse?format=json&lat=37.325460&lon=-121.777310 Which work in my browser. This is my code:

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 "";
   }
}

But I get the following Error: "SSL Exception"

The SSL code has been copied from other StackOverlfow posts given as an answer but it doesn't seem to work here?

Upvotes: 0

Views: 169

Answers (1)

user1978816
user1978816

Reputation: 822

As soon as I posted I realized my failure. I used the HTTP port 80, for SSL HTTPS you need port 443 (typically).

As soon as I changed that it was fine. Other SO posts didn't point out the obvious for overly tried engineers switching HTTP code, so I hope this is helpful.

Upvotes: 1

Related Questions