day1 基础依赖
org.apache.httpcomponents httpclient 4.5.2 需要抛出一个异常 //1.打开浏览器 创建HttpClient对象 CloseableHttpClient httpClient = HttpClients.createDefault();//2.输入网址 发起get请求 创建httpget对象
HttpGet httpGet=new HttpGet("http://www.itcast.com");
//3.按回车 发起请求 返回响应 使用httpclient对象发起请求
CloseableHttpResponse response = httpClient.execute(httpGet);
//4.解析相应 获取数据
//4.1判断状态码
if(response.getStatusLine().getStatusCode()==200){
HttpEntity entity = response.getEntity();//响应体
String content = EntityUtils.toString(entity, "utf8");
System.out.println(content);
}