Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple GET Request with Apache HTTP Client
package de.christianbergau;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
public class HttpClientApp {
public static void main(String... args) {
int timeout = 3;
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout * 1000)
.setSocketTimeout(timeout * 1000)
try (CloseableHttpClient client = HttpClientBuilder.create()
.build()) {
HttpGet request = new HttpGet("");
HttpResponse response = client.execute(request);
} catch (IOException e) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.