如何使用Spring RestTemplate遵循PUT请求的重定向?

时间:2019-07-16 13:45:58

标签: java spring

我正在尝试对PUT请求进行重定向。 LaxRedirectStrategy支持除PUT方法之外的其他HTTP方法。如何跟踪重定向?

LaxRedirectStrategy:

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);

用于创建响应的代码:

ResponseEntity<String> responseEntity = restTemplate.exchange(uri, HttpMethod.PUT, entity, String.class);

0 个答案:

没有答案