如何从 Spring RestTemplate GET 请求中获取 Response Header 信息
How to get Response Header information from Spring RestTemplate GET request
我正在触发 GET
请求并通过 Spring RestTemplate
成功获取 JSON
数据。我也想获取 Response Header
信息,但我不确定如何获取它。
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
我正在触发 GET
请求并通过 Spring RestTemplate
成功获取 JSON
数据。我也想获取 Response Header
信息,但我不确定如何获取它。
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