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