maven引用:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>example:
String resultJson = null;
CloseableHttpClient httpclient = HttpClients.createDefault();
String url = "http://xxxx";
HttpPost httpPost = new HttpPost(url);
List <NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("qqq", "xx"));
httpPost.setEntity(new UrlEncodedFormEntity(params,Charset.forName("UTF-8")));
CloseableHttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
String entityStr = EntityUtils.toString(entity);
JSONObject jsonObject = JSONObject.fromObject(entityStr);
本文介绍如何使用Maven依赖管理工具引入Apache HttpClient 4.5.1版本,并提供了一个简单的HTTP POST请求示例,展示了如何设置请求参数并解析响应。
1万+

被折叠的 条评论
为什么被折叠?



