/**
* 请求退款URL
*/
@Value("${request.returnpayurl}")
private String requestReturnpayurl;
//发送退款请求
String returnString = postByString(requestReturnpayurl, params, "text/xml");
/**
* 发送POST请求
*
* @param url
* @param params
* @param bodyType
* @return
*/
private String postByString(String url, String params, String bodyType) {
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(url);
try {
StringRequestEntity entity = new StringRequestEntity(params, bodyType, "UTF-8");
postMethod.setRequestEntity(entity);
httpClient.executeMethod(postMethod);
if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
String response = new String(postMethod.getResponseBodyAsString());
return response;
} else {
return null;
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
postMethod.releaseConnection();
}
return null;
}