public static String connectToBytterForpay(Context context, String xml, String WSDLAddress) throws Exception{
HttpURLConnection connection = null;
StringBuffer sb = new StringBuffer();
OutputStream os = null;
InputStream is = null;
try{
URL u = new URL(WSDLAddress);
connection = (HttpURLConnection)u.openConnection();
connection.setConnectTimeout(15000);
connection.setReadTimeout(60000);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
connection.setRequestProperty("SOAPAction", "bossWebService");
connection.setDoOutput(true);
os = connection.getOutputStream();
String soapBody = "<![CDATA[" + xml + "]]>";//具体报文,用<![CDATA[ ]]>包起来
sb.append(
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://server.webservice.standard.erp.hibernate.byttersoft.com\"><soapenv:Header/><soapenv:Body><ser:PaymentSysXmlData><ser:payXml>");
sb.append(soapBody);
sb.append("</ser:payXml></ser:PaymentSysXmlData></soapenv:Body></soapenv:Envelope>");
os.write(sb.toString().getBytes("utf-8"));
os.flush();
sb = new StringBuffer();
is = connection.getInputStream();
String line = "";
for(BufferedReader in = new BufferedReader(new InputStreamReader(is, "utf-8")); in.ready(); sb
.append(line))
{
line += in.readLine();
}
MessageFactory msgFactory;
msgFactory = MessageFactory.newInstance();
SOAPMessage reqMsg =
msgFactory.createMessage(new MimeHeaders(), new ByteArrayInputStream(line.getBytes("utf-8")));
reqMsg.saveChanges();
SOAPBody body = reqMsg.getSOAPBody();
Iterator<SOAPElement> iterator = body.getChildElements();
String rcvxml = "";
while(iterator.hasNext()){
SOAPElement element = (SOAPElement) iterator.next();
if(element.getNodeName().equals("ns:PaymentSysXmlDataResponse")) {
Iterator<SOAPElement> iterator_out = element.getChildElements();
while(iterator_out.hasNext()){
SOAPElement element_out = (SOAPElement) iterator_out.next();
if(element_out.getNodeName().equals("ns:return")) {
rcvxml = element_out.getValue();
}
}
}
}
return rcvxml;
}
catch(Exception e){
throw new RuntimeException(BytterConst.SYSTEMNAME + e);
}
finally{
if(connection != null) {
connection.disconnect();
}
try{
if(null != is) {
is.close();
}
if(null != os) {
os.close();
}
}
catch(IOException e){
throw new RuntimeException(BytterConst.SYSTEMNAME + e);
}
}
}