Java examples for Network:apache http
Client GZip Content Compression using apache http
import java.io.IOException; import org.apache.http.client.ResponseHandler; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; public class ClientGZipContentCompression { public static void main(String[] args) { RequestConfig config = RequestConfig.custom() .setSocketTimeout(1000).setConnectionRequestTimeout(1000) .build();//from www. ja va 2 s. c o m try (CloseableHttpClient httpclient = HttpClients.custom() .setDefaultRequestConfig(config).build()) { HttpGet httpget = new HttpGet("https://www.google.co.kr"); System.out.println("executing req = " + httpget.getURI()); ResponseHandler<String> resHandler = new BasicResponseHandler(); String resBody = httpclient.execute(httpget, resHandler); System.out.println("------------------------------------"); System.out.println(resBody); System.out.println("------------------------------------"); } catch (IOException e) { e.printStackTrace(); } finally { } } }