Zeeshan
Zeeshan

Reputation: 12421

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

Upvotes: 2

Views: 14925

Answers (1)

codependent
codependent

Reputation: 24452

ResponseEntity<JsonVO> responseEntity =  restTemplate.getForEntity(url, JsonVO.class, vars);
JsonVO jsonVO = responseEntity.getBody();
HttpHeaders headers = responseEntity.getHeaders(); //<-- your headers

Upvotes: 5

Related Questions