我找到了解决方案,通过使用HttpURLConnection的而不是RestTemplate:
HttpURLConnection con = getHttpURLConnection();
try {
con.setInstanceFollowRedirects(true);
con.setRequestProperty(requestHeaderName, requestHeaderValue);
HttpURLConnection.setFollowRedirects(true);
con.getResponseCode();
verifyResponseCode(con);
String redirectPath = con.getURL().toString();
return new RedirectView(redirectPath);
} catch (RestClientException e) {
log.error(e.getMessage(), e);
throw e;
}
而在getHttpURLConnection:
HttpURLConnection getHttpURLConnection() throws Exception {
URL securedUrl = new URL("URL");
return (HttpURLConnection) securedUrl.openConnection();
}
现在它为我工作。 con.getURL()返回来自外部服务的重定向URL,现在我可以访问它。
它取决于底层http库,你知道你在使用哪个? – Taylor
感谢您的及时回应。 这是spring-web-4.3.6.RELEASE – saeedj
这不是http库。这可能是apache http或okhttp或者其他的。找出这是什么,并看看配置。它比春天低。 – Taylor