apache HttpClient

时间:2019-10-19 18:23:07   收藏:0   阅读:59

技术分享图片

 

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.HttpClients;

import java.io.IOException;
import java.util.Scanner;

public class HCL {
    public static void main(String[] args) {
        CloseableHttpClient httpclient= HttpClients.createDefault();
        HttpGet httpGet=new HttpGet("http://www.baidu.com");
        try {
            HttpResponse httpResponse=httpclient.execute(httpGet);
            Scanner sc = new Scanner(httpResponse.getEntity().getContent());

            //Printing the status line
            System.out.println(httpResponse.getStatusLine());
            while(sc.hasNext()){
                System.out.println(sc.nextLine());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

原文:https://www.cnblogs.com/lccsblog/p/11704455.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!