其他分享
首页 > 其他分享> > Post请求使用params传参

Post请求使用params传参

作者:互联网

直接上代码
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);//获取响应

标签:传参,entry,pairList,param,params,postMethod,put,new,Post
来源: https://blog.csdn.net/Yurin_/article/details/120820793