直接上代码
public static void main(String[] args) throws Exception {
//创建浏览器
CloseableHttpClient httpClient = HttpClients.createDefault();
//输入访问的地址
HttpPost httpPost = new HttpPost("https://www.douban.com/");
//点击回车,访问地址,拿到返回数据
CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
//解析数据
if (httpResponse.getStatusLine().getStatusCode() == 200) {
//获得返回的entity
HttpEntity entity = httpResponse.getEntity();
//将entity转换成字符串
System.out.println(EntityUtils.toString(entity, "utf-8"));
}
}
```