发布网友 发布时间:2022-04-23 09:51
共1个回答
热心网友 时间:2022-04-27 17:13
//serverURL url地址
HttpPost httpPost = new HttpPost(serverURL);
//param 为参数
StringEntity entity = new StringEntity(param);
entity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(httpPost);
还可以用map作为参数
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
if(param!=null){
Set set = param.keySet();
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
Object value = param.get(key);
formparams.add(new BasicNameValuePair(key.toString(), value.toString()));
}
}