HttpPost方式发送数据

阅读更多
/**
* doPost方式发送数据

*
* @param url
* @param header
* @param param
* @return
*/
private static HttpPost doPost(String url, Map header,
Map param) {
HttpPost post = new HttpPost(url);
if (header != null) {
for (Map.Entry entry : header.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
post.setHeader(key, value);
}
}
List nvp = new ArrayList();
for (Map.Entry entry : param.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
nvp.add(new BasicNameValuePair(key, value));
}
try {
UrlEncodedFormEntity params = new UrlEncodedFormEntity(nvp);
post.setEntity(params);
} catch (Exception e) {
e.printStackTrace();
}
return post;
}

你可能感兴趣的:(httpclient,HttpPost,doPost,params)