public static String postHttp(JSONObject jsonObject, String jsonUrl){
String responseMsg="";
//获取http连接
HttpClient httpClient = new HttpClient();
httpClient.getParams().setContentCharset("utf-8");
//2.构造PostMethod的实例
PostMethod postMethod=new PostMethod(jsonUrl);
try {
String postJson = jsonObject.toJSONString();
RequestEntity se = new StringRequestEntity(postJson, "application/json", "UTF-8");
//url设置json参数
postMethod.setRequestEntity(se);
postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
try {
//发送url 单独处理该异常
httpClient.executeMethod(postMethod);//200
} catch (Exception e) {
try {
httpClient.executeMethod(postMethod);//200
} catch (Exception e2) {
try {
httpClient.executeMethod(postMethod);//200
} catch (Exception e3) {
log.error("连续3次连接异常,终止数据推送...",e);
}
}
}
responseMsg=postMethod.getResponseBodyAsString().trim();
} catch (Exception e) {
e.printStackTrace();
}finally{
//7.释放连接
postMethod.releaseConnection();
}
return responseMsg;
}