Skip to content

Instantly share code, notes, and snippets.

@yarinkos
Created January 22, 2019 09:30
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 yarinkos/c943d4174f68957b4c110c0ea6d3ed2a to your computer and use it in GitHub Desktop.
Save yarinkos/c943d4174f68957b4c110c0ea6d3ed2a to your computer and use it in GitHub Desktop.
RestTemplate request (basic auth )
RestTemplate restTemplate = new RestTemplate();
restTemplate.getInterceptors().add(
new BasicAuthorizationInterceptor("user", "password"));
String url = "YOUR_URL";
ResponseEntity<String> response = null;
try {
response = restTemplate.exchange(url,
HttpMethod.GET, null, String.class);
log.info(response.getBody().toString());
} catch (HttpStatusCodeException e) {
//e.printStackTrace();
if (e.getStatusCode().value() == 401) {
log.info("401");
} else {
log.info(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment