gpt4 book ai didi

ssl - HTTPS 使用 Poco C++ 获取 SSL 异常 : OSM Nominatim

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:00 25 4
gpt4 key购买 nike

我正在尝试向 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 帖子中复制,但它似乎在这里不起作用?

最佳答案

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

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

关于ssl - HTTPS 使用 Poco C++ 获取 SSL 异常 : OSM Nominatim,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50610525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com