第一节 HttpClient简介及第一个demo
1.模拟get及post请求
2.引用httpCllient
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.2</version>
</dependency>
3.demo
public class MyHttpClient {
@Test
public void test1(){
try {
//放置响应结果
String result ;
//get方法-请求http://www.baidu.com
HttpGet get = new HttpGet("http://www.baidu.com");
//获取DefaultHttpClient请求
HttpClient client = HttpClientBuilder.create().build();
//执行get方法
HttpResponse response = client.execute(get);
//拿到响应结果的实体entity
result = EntityUtils.toString(response.getEntity(),"utf-8");
System.out.println(result);
} catch (IOExcepti