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);//获取响应

上一篇:Java泛型练习题


下一篇:多线程之ThreadLocal源码分析