Created
February 2, 2018 21:50
-
-
Save LenarBad/224751f163781594b2dfb135535fda04 to your computer and use it in GitHub Desktop.
How to send GET Request and get Response with Apache Http Components
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
String url = "https://www.some-web-service/api/endpoint"; | |
HttpGet get = new HttpGet(url); | |
Header headers[] = { new BasicHeader("Accept", "application/json")}; | |
get.setHeaders(headers); | |
CloseableHttpClient client = HttpClients.custom().build(); | |
HttpResponse response = client.execute(get); | |
String result = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); | |
int responseCode = response.getStatusLine().getStatusCode(); | |
String statusPhrase = response.getStatusLine().getReasonPhrase(); | |
response.getEntity().getContent().close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment