public static String sendHttpPostIns(String url, String param) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse httpResponse = null;
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(param));
//httpPost.setEntity(new StringEntity(param,"utf-8"));
httpPost.addHeader("Content-type","application/json; charset=utf-8");
httpPost.setHeader("Accept", "application/json");
HttpEntity entity = httpclient.execute(httpPost).getEntity();
if (entity == null) {
return null;
}
String data = EntityUtils.toString(entity, Consts.UTF_8);
if (StringUtil.isEmpty(data)) {
return null;
}
return data;
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e);
}finally {
if(httpResponse!=null){
httpResponse.close();
}
if(httpclient!=null){
httpclient.close();
}
}
}