HttpPost方式发送数据

/**
* doPost方式发送数据<br>
*
* @param url
* @param header
* @param param
* @return
*/
private static HttpPost doPost(String url, Map<String, String> header,
Map<String, String> param) {
HttpPost post = new HttpPost(url);
if (header != null) {
for (Map.Entry<String, String> entry : header.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
post.setHeader(key, value);
}
}
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> 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,params,dopost)