简体   繁体   中英

How to get Response Header information from Spring RestTemplate GET request

I am triggering a GET request and getting the JSON data successfully via Spring RestTemplate . I also want to get the Response Header information but I am not sure how to get it.

private String getAPIKeySpring() {
        RestTemplate restTemplate = new RestTemplate();
        String url = baseURL+"/users/apikey";
        Map<String, String> vars = new HashMap<String, String>();
        vars.put("X-Auth-User", apiUser);
        JsonVO jsonVO =  restTemplate.getForObject(url, JsonVO.class, vars);
        System.out.println(jsonVO);
        return null;
    }
ResponseEntity<JsonVO> responseEntity =  restTemplate.getForEntity(url, JsonVO.class, vars);
JsonVO jsonVO = responseEntity.getBody();
HttpHeaders headers = responseEntity.getHeaders(); //<-- your headers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM