ApacheHttpClient:初次使用的简单Demo(用来访问百度)

当前环境: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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值