一、get请求
1.1不带参数
public static void main(String[] args) throws Exception {
// https://www.baidu.com/s?ie=UTF-8&wd=httpClient
// 1:相当于打开浏览器
CloseableHttpClient httpClient = HttpClients.createDefault();
// 2:创建一个get的请求方式
HttpGet httpGet = new HttpGet("http://www.baidu.com/");
// 3:执行了get请求
CloseableHttpResponse response = httpClient.execute(httpGet);
// 4:获取返回的数据
// 200:正常
// 404:找不到资源
if( response.getStatusLine().getStatusCode()==200){// 如果状态码是200 表示正常返回了
// 把返回的内容转成字符串
String content = EntityUtils.toString(response.getEntity(), "utf-8");
System.out.println(content);
}
}