<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpGet httpGet = new HttpGet("http://example.com/api/resource");
httpGet.addHeader("Accept", "application/json");
CloseableHttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
String responseBody = EntityUtils.toString(entity, "UTF-8");
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.1</version>
</dependency>
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://example.com/api/resource")
.addHeader("Accept", "application/json")
.build();
Response response = client.newCall(request).execute();
String responseBody = response.body().string();
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.9</version>
</dependency>
RestTemplate restTemplate = new RestTemplate();
String responseBody = restTemplate.getForObject("http://example.com/api/resource", String.class);