1、最近太累了,好困。闲话少许直奔主题吧。上代码
try{
String wsurl = "http://172.16.16.236:9999/xxx/ws/WSService?wsdl";
String Str = "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wss="http://wsservice.userInfo.uias.jit.com/"> <soapenv:Header /> <soapenv:Body> <wss:synchronizeDatas> <appMark>TEST</appMark> <utsNodeInfo><![CDATA[<?xml version="1.0" encoding="UTF-8"?><datas><data><id>#id#</id></data></datas>]]></utsNodeInfo></wss:synchronizeDatas></soapenv:Body></soapenv:Envelope>";
byte[] content;
content = Str.getBytes("UTF-8");
HttpClient httpClient = new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
PostMethod method = new PostMethod(url);
httpClient.getParams().setContentCharset("UTF-8");
method.setRequestHeader("Connection", "close");
RequestEntity requestEntity = new ByteArrayRequestEntity(content,
"application/xml; charset=UTF-8");
method.setRequestEntity(requestEntity); int statusCode = httpClient.executeMethod(method);
if(statusCode==200){
String xmlStr =method.getResponseBodyAsString();
Document document = DocumentHelper.parseText(xmlStr);
Element root = document.getRootElement();
Element body = root.element("Body");
Element response = (Element) body.elements().get(0);
Element pst = (Element) response.elements().get(0);
Element retCode = pst.element("code");
String a = retCode.getText();
code = a.charAt(0);
Element id = pst.element("id");
i = id.getText();
Element message = pst.element("message");
m = message.getText();
} }catch(Exception e){
e.printStackTrace();
log.error(e.getMessage(), e);
}
2、其实整体也没什么特别,但是有一个地方要注意就是<![CDATA[]]>的引用。