2023-02-26 395
HttpClient Get Example
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("https://www.baidu.com");
CloseableHttpResponse response = httpClient.execute(httpGet);
try {
//获取response的响应状态
System.out.println(response.getStatusLine());
//获取响应内容
HttpEntity entity = response.getEntity();
//确保被消耗
EntityUtils.consume(entity);
} finally{
response.close();
}
HttpClient Post Example — 这个url是不行的,可以找个http post的请求url进行尝试
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://www.baidu.com");
//设置请求参数
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", "test"));
params.add(new BasicNameValuePair("password", "test"));
httpPost.setEntity(new UrlEncodedFormEntity(params));
CloseableHttpResponse response = httpClient.execute(httpPost);
try {
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
} finally {
response.close();
}
原文链接:https://www.77isp.com/post/34548.html
=========================================
https://www.77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态