英文:
tls: no application protocol negotiated
问题
第一次使用libnghttp2-asio库,尽管它已经不推荐使用。
我正在尝试如何获取reddit网页,如下所示:
boost::system::error_code ec;
namespace net = nghttp2::asio_http2;
namespace ssl = boost::asio::ssl;
using boost::asio::ip::tcp;
boost::asio::io_context ioc;
ssl::context tls(ssl::context::tlsv12_client);
tls.set_options(ssl::context::default_workarounds);
// tls.set_verify_mode(boost::asio::ssl::verify_peer);
tls.set_verify_mode(ssl::verify_none);
tls.set_default_verify_paths();
net::client::session session(ioc, tls, "www.reddit.com", "443");
session.on_connect([&session](tcp::resolver::iterator endpoint_it) {
std::cout << "Connected" << std::endl;
});
session.on_error([](const boost::system::error_code &ec) {
std::cout << "error: " << ec.message() << std::endl;
});
ioc.run();
输出:
error: tls: no application protocol negotiated
我想知道如何成功连接,也许我错过了握手过程?如果是这样,应该如何操作?
英文:
First time to using the libnghttp2-asio library despite it being deprecated.
I'm experimenting how I think would give the reddit webpage as follows:
boost::system::error_code ec;
namespace net = nghttp2::asio_http2;
namespace ssl = boost::asio::ssl;
using boost::asio::ip::tcp;
boost::asio::io_context ioc;
ssl::context tls(ssl::context::tlsv12_client);
tls.set_options(ssl::context::default_workarounds);
// tls.set_verify_mode(boost::asio::ssl::verify_peer);
tls.set_verify_mode(ssl::verify_none);
tls.set_default_verify_paths();
net::client::session session(ioc, tls, "www.reddit.com", "443");
session.on_connect([&session](tcp::resolver::iterator endpoint_it) {
std::cout << "Connected" << std::endl;
});
session.on_error([](const boost::system::error_code &ec) {
std::cout << "error: " << ec.message() << std::endl;
});
ioc.run();
Output:
error: tls: no application protocol negotiated
I would like to know how I can connect successfully, perhaps I'm missing the handshake procedure? If so, how should I do it?
答案1
得分: 2
nghttp2默认不支持ALPN。
通过以下方法解决:
SSL_CTX_set_alpn_protos(tls.native_handle(), (const unsigned char *)"\x02h2", 3);
英文:
nghttp2 doesn't do ALPN by default.
Solved by
SSL_CTX_set_alpn_protos(tls.native_handle(), (const unsigned char *)"\x02h2", 3);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论