1. 程式人生 > >HttpClient Post提交 不帶引數

HttpClient Post提交 不帶引數

/*
	 * HttpClient Post提交 不帶引數
	 */
	@Test
	public void fun3() throws ClientProtocolException, IOException{
		//1、建立HttpClient
		CloseableHttpClient clients = HttpClients.createDefault();
		//2、建立HttpPost
		HttpPost post = new HttpPost("http://localhost:8080/itcast297/loginAction_login");
		
		//3、執行請求
		CloseableHttpResponse response = clients.execute(post);
		
		//4獲取實體
		HttpEntity entity = response.getEntity();
		
		//將實體轉換成字串
		System.out.println(EntityUtils.toString(entity));
		
		response.close();
		
	}