RestTemplate 支持服务器内302重定向

时间:2023-03-08 16:53:18
Stack Overflow 里找到的代码,可以正常返回服务器302重定向后的响应
final RestTemplate restTemplate = new RestTemplate();
final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
final HttpClient httpClient = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.build();
factory.setHttpClient(httpClient);
restTemplate.setRequestFactory(factory);