HttpClient Get请求不带参数

	/*
		 * HttpClient Get请求不带参数
		 */
		@Test
		public void fun() throws Exception{
			
			//1、创建客户端
			CloseableHttpClient client = HttpClients.createDefault();
			//2、创建HttpGet对象
			HttpGet httpGet = new HttpGet("http://localhost:8080/itcast297/");
			//3、执行get请求
			CloseableHttpResponse response = client.execute(httpGet);
			//4、获取响应实体
			HttpEntity entity = response.getEntity();
			//5、获取响应状态
			System.out.println(response.getStatusLine());
			if(entity!=null){
				//获取响应内容的长度
				System.out.println(entity.getContentLength());
				//获取响应内容
				System.out.println(EntityUtils.toString(entity));
			}
			
	//		6、关闭
			response.close();
		}

猜你喜欢

转载自blog.csdn.net/shishize55/article/details/83759118