Rest模板中IP地址和域名的不同场景

时间:2019-05-26 06:33:48

标签: spring resttemplate

我有一个休息模板代码,如下:

  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" 

从邮递员那里可以正常工作,唯一的问题是其余模板调用。

如何解决此问题?

0 个答案:

没有答案