java - 如何使用 HttpComponents (Java apache lib) 发出请求,更改 TLS 握手中的服务器名称指示

标签 java ssl https tls1.2 apache-httpcomponents

我必须使用 TLS 证书和私钥向后端发出请求,在故障排除中,在服务器名称指示中使用相同的主机名时出现错误。请参阅:

我遇到错误:

openssl s_client -connect endpoint.com:443 -servername endpoint.com

我成功了:

openssl s_client -connect endpoint.com:443 -servername another_endpoint_name.com

但是我找不到更改 Apache Lib 中 TLS 握手 中服务器名称指示的方法。 这可能吗?

相关问题:How to set SNI (Server Name Indication) in TLS Handshake using Apache HttpComponents Java

最佳答案

可以通过使用 HttpHost 和已解析的 InetAddress 来创建自定义请求路由。

尝试一下这段代码,让我知道是否有效。

CloseableHttpClient httpClient = HttpClients.createSystem();
HttpHost host = new HttpHost(InetAddress.getByName("endpoint.com"), "another_endpoint_name.com", -1, "https");
try (CloseableHttpResponse response = httpClient.execute(host, new HttpGet("https://another_endpoint_name.com/stuff"))) {
    System.out.println(response.getStatusLine());
    EntityUtils.consume(response.getEntity());
}

关于java - 如何使用 HttpComponents (Java apache lib) 发出请求,更改 TLS 握手中的服务器名称指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59793862/

相关文章:

java - 检查两个集合是否至少包含一个相同元素的快速方法

facebook-graph-api - Facebook Canvas 应用开发的 SSL 证书要求

ssl - 如何使用haproxy解密和加密HTTPS流量?

.net - ASP.Net https 与 http

ssl - Wamp2 和 "The ordinal 942 could not be located in the dynamic link library LIBEAY.dll"

java - 使用 Thymeleaf 实现 JPA 验证消息国际化

java - 如何在不返回值的情况下显示消息

java - 我的 Eclipse 中的 android 项目消失了?

ssl - 无法在 Nginx 上禁用 TLSv1

http - 如何使用 Kubernetes Nginx 入口 Controller 禁用对服务的 http 访问?