// get请求
public static void httpget() throws Exception {
CloseableHttpClient client = HttpClients.createDefault();
String url = "https://www.wzywl.com?page=1";
HttpGet get = new HttpGet(url);
// 发送请求
CloseableHttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
if(entity != null) {
String result = EntityUtils.toString(entity);
System.out.println(result);
}
}
// post请求
public static void httppost() throws Exception {
CloseableHttpClient client = HttpClients.createDefault();
String url = "https://www.wzywl.com";
HttpPost post = new HttpPost(url);
// 参数
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("name", "zhangsan"));
params.add(new BasicNameValuePair("password", "123"));
CloseableHttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
if(entity != null) {
String result = EntityUtils.toString(entity);
System.out.println(result);
}
}