如何使用 boost::beast 启用 TLS SNI
首先包含所需的头文件:
enable_tls_sni_boostbeast.cpp
#include <openssl/ssl.h>一旦初始化了 boost::beast::ssl_stream,添加以下代码(其中 host 是包含要连接主机名的 std::string,如 api.ipify.org):
tls_sni_set_hostname.cpp
if(!SSL_set_tlsext_host_name(stream.native_handle(), host.c_str())) {
beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
throw beast::system_error{ec};
}原始来源:boost::beast 官方 HTTPS 客户端示例
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow