Skip to content

Instantly share code, notes, and snippets.

@royclarkson
Created April 27, 2012 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royclarkson/2512502 to your computer and use it in GitHub Desktop.
Save royclarkson/2512502 to your computer and use it in GitHub Desktop.
Http Basic Auth in Rest Template
HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAuthorization(authHeader);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Object> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<Object>(requestHeaders), Object.class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment