我必须使用 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/