首页 > Web开发 > 详细

apache HttpClient

时间:2019-10-19 18:23:07      阅读:53      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

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

 

apache HttpClient

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!