-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathApacheHttpClientGet.java
35 lines (25 loc) · 1.05 KB
/
ApacheHttpClientGet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.zetcode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
public class ApacheHttpClientGet {
public static void main(String[] args) throws IOException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpGet request = new HttpGet("http://www.something.com");
HttpResponse response = client.execute(request);
BufferedReader bufReader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
StringBuilder builder = new StringBuilder();
String line;
while ((line = bufReader.readLine()) != null) {
builder.append(line);
builder.append(System.lineSeparator());
}
System.out.println(builder);
}
}
}