直接上代码
Map<String, Object> param = new HashMap<>();
param.put("参数1", "value1");
param.put("参数2", "value2");
param.put("参数3", "value3");
List<NameValuePair> pairList = new ArrayList<>();
for(Map.Entry<String, Object> entry:param.entrySet()){
pairList.add(new BasicNameValuePair(entry.getKey(),entry.getValue().toString()));
}
HttpPost postMethod = new HttpPost(url);//传入URL地址
//此处可以对postmethod进行配置
postMethod.setEntity(new UrlEncodedFormEntity(pairList));
HttpResponse response = httpClient.execute(postMethod);//获取响应
Post请求使用params传参
最新推荐文章于 2023-09-06 15:28:15 发布
本文介绍了如何使用Java实现HTTP Post方法,通过Map和NameValuePair将参数组装,并通过HttpPost和HttpClient发送到指定URL。重点在于参数的组织和HTTP客户端的使用。
1318

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



