我有一个休息模板代码,如下:
HttpHeaders headers = new HttpHeaders();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication != null) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
if (!authorities.contains(new SimpleGrantedAuthority(ROLE_ANONYMOUS_USER))) {
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
OAuth2AccessToken accessToken = tokenStore.readAccessToken(details.getTokenValue());
headers.set(AUTHORIZATION, BEARER + accessToken);
}
}
ResponseEntity<Foo> responseEntity = restTemplate.exchange(<Domain name> + "/foo/1"
, HttpMethod.GET, new HttpEntity(headers) , Foo.class);
这给了我400错误的要求。但是,如果我使用服务器的IP地址和端口号,就可以使用域。
也是网址:
<Domain name> + "/foo/1"
从邮递员那里可以正常工作,唯一的问题是其余模板调用。
如何解决此问题?