//下面是一个demo:
package test; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.apache.http.client.methods.HttpPost; import java.io.IOException; public class HttpPost1 { public static void main(String[] args) { //1.打开浏览器 CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost=new HttpPost("https://www.itcast.cn"); //2.输入网址 CloseableHttpResponse response = null; try { response = httpClient.execute(httpPost); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String s = EntityUtils.toString(entity, "utf-8"); System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } finally { try { response.close(); } catch (IOException e) { e.printStackTrace(); } try { httpClient.close(); } catch (IOException e) { e.printStackTrace(); } } } }
标签:Java,--,http,IOException,org,apache,import,Post,response From: https://www.cnblogs.com/daitu66/p/17561130.html