一、java发送post请求
public String sendPost(String url, Map dataMap) {
String result = "";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
List params = new ArrayList();
params.add(new BasicNameValuePair("charset", "UTF-8"));// 压缩使用UTF-8
if (dataMap != null && !dataMap.isEmpty()) {
for (String key : dataMap.keySet()) {
params.add(new BasicNameValuePair(key, dataMap.get(key)));
}
}
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response2 = httpclient.execute(httpPost);
HttpEntity entity2 = response2.getEntity();
result = EntityUtils.toString(entity2);
EntityUtils.consume(entity2);
} catch (UnsupportedEncodingException e) {