当前环境:httpclient 4.5.6
1.简介
当前例子来源于:apache-httpclient的入门demo
当前学习资源来自apache中的httpclient(一个用于简化访问http服务器的http客户端),这里盗一波图:

2.pom依赖
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
3.使用httpclient访问百度
public static void main(String[] args) throws IOException {
// 创建一个默认可以关闭的HTTP客户端,用于访问HTTPServer端
CloseableHttpClient httpclient = HttpClients.createDefault();
// 创建一个get请求用于访问当前的百度地址
HttpGet httpGet = new HttpGet("http://www.baidu.com");
//这里可以使用HttpPost httpPost=new HttpPost("http://www.baidu.com");
//创建post请求
CloseableHttpResponse response = null;
try {
// 通过当前的客户端执行当前的get请求并获得响应结果
response = httpclient.execute(httpGet

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



