Created
January 22, 2019 09:30
-
-
Save yarinkos/c943d4174f68957b4c110c0ea6d3ed2a to your computer and use it in GitHub Desktop.
RestTemplate request (basic auth )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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