集册 Java实例教程 使用apache http的客户端GZip内容压缩

使用apache http的客户端GZip内容压缩

欢马劈雪     最近更新时间:2020-01-02 10:19:05

472
使用apache http进行客户端GZip内容压缩


import java.io.IOException;
// 来自 N o w  J a v a  . c o m

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();

        try (CloseableHttpClient httpclient = HttpClients.custom()

                .setDefaultRequestConfig(config).build()) {/**时 代 J a v a 公 众 号 - N o w J a v  a . c o m**/

            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("------------------------------------");

            
展开阅读全文