如何使用 RestTemplate 或 HttpClient 在 https 中请求具有不同服务器 IP 的 uri

问题描述 投票:0回答:0

如何使用 RestTemplate 或 HttpClient 在 https 中请求具有不同服务器 IP 的 uri

例如,我有这些日志:

xxx.co,183.245.61.4
xxx.co,183.246.179.
xxx.co,183.246.94.5
xxx.co,211.140.42.9
xxx.co,211.140.45.6
xxx.co,223.92.69.16
xxx.co,223.93.10.22
xxx.co,223.93.70.14
xxx.co,223.94.54.18
xxx.co,223.95.121.4
xxx.co,223.95.160.1
xxx.co,223.95.207.1
xxx.co,223.95.212.2
xxx.co,39.170.101.6
xxx.co,39.171.55.17
xxx.co,39.172.89.12
xxx.co,39.175.22.10
xxx.co,39.184.140.6

当我在 http:

中这样做时
@GetMapping("/public/test")
public ResponseEntity<String> test(@RequestParam(required = false) String host) {
    HttpHeaders headers = new HttpHeaders();
    if (StringUtils.isNotBlank(host)) {
        headers.add(HttpHeaders.HOST, host);
    }
    var res = restTemplate.exchange("http://xxx.xxx.xxx.xxx/", HttpMethod.GET, new HttpEntity<>(headers), String.class);
    return res;
}

一切都好,
但在 https.

https 需要 SNI(Server Name Indication)
我试图找到手动设置 SNI 的方法,
但它没有用(没有名为 setSNI() 的方法)

为什么我需要这样做是因为不同的IP来处理我的请求会给出不同的结果。

java request httpclient okhttp resttemplate
© www.soinside.com 2019 - 2024. All rights reserved.