京-pk发型不乱CEO<
wuraolong@126.com> 23:33:00
public String executeHttpRequest(String url, String requestContent,Log log) {
Log logHttp= log; //logHttp对应的可能是开放平台、酒店开放平台、酒店
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(url);
try {
postMethod.setRequestEntity(new StringRequestEntity(requestContent, "text/xml; charset=" + charSet, charSet));
postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, charSet);
postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, soTimeOut);
int statusCode = client.executeMethod(postMethod);
BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream(), charSet));
StringBuffer sb = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
sb.append(line);
}
in.close();
if (statusCode != HttpStatus.SC_OK) {
logHttp.error("Method:HttpClientUtil.executeHttpRequest---->请求返回状态不为200,url:" + url + ",返回结果:" + sb.toString());
return "";
}
logHttp.info("Method:HttpClientUtil.executeHttpRequest---->请求返回状态为200,url:" + url + ",返回结果:" + sb.toString());
return sb.toString();
}
catch (Exception e) {
logHttp.error("Method:HttpClientUtil.executeHttpRequest---->发生异常!请检查网络和参数", e);
}
finally {
postMethod.releaseConnection();
}
return null;
}
}