java+soap风格接口调用
private String getResult(String url, String xml) throws Exception {
PostMethod postMethod = new PostMethod(url);
// 然后把Soap请求数据添加到PostMethod中
byte[] b = xml.getBytes("utf-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length);
RequestEntity re = new InputStreamRequestEntity(is, b.length,"text/xml; charset=UTF-8");
postMethod.setRequestEntity(re);
// 最后生成一个HttpClient对象,并发出postMethod请求
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
String soapResponseData= "";
if(statusCode == 200) {
log.info("调用成功!");
soapResponseData = postMethod.getResponseBodyAsString();
}
else {
log.info("调用失败!错误码:" + statusCode);
}
return soapResponseData;
}