HTTP get with headers using RestTemplate
The RestTemplate getForObject() method does not support setting headers. The solution is to use the exchange() method. So instead of restTemplate.getForObject(url, String.class, param) (which has no headers), use HttpHeaders headers = new HttpHeaders(); headers.set(“Header”, “value”); headers.set(“Other-Header”, “othervalue”); … HttpEntity<Void> requestEntity = new HttpEntity<>(headers); ResponseEntity<String> response = restTemplate.exchange( url, HttpMethod.GET, requestEntity, String.class, param); Finally, use response.getBody() … Read more