public class XmlService {
public String query(String num) throws Exception {
InputStream in = this.getClass().getClassLoader().getResourceAsStream("query.xml");
byte[] data = LoadUtils.load(in);
String xml = new String(data);
//替换
xml = xml.replace("#", num);
byte[] sendData = xml.getBytes("UTF-8");
//发送到代理的地址上
URL url = new URL("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
conn.setRequestProperty("Content-Length", String.valueOf(sendData.length));
//将请求的xml发送出去
conn.setDoOutput(true);
conn.getOutputStream().write(sendData);
//获取从服务器传回来的数据
if (conn.getResponseCode() == 200)
return parse(conn.getInputStream());
return null;
}
//解析流拿到getMobileCodeInfoResult中的数据
private String parse(InputStream inputStream) throws Exception {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(inputStream, "UTF-8");
//查找getMobileCodeInfoResult标签,获取标签中的数据
for (int event = parser.getEventType(); event != XmlPullParser.END_DOCUMENT; event = parser.next())
switch (event) {
case XmlPullParser.START_TAG:
if ("getMobileCodeInfoResult".equals(parser.getName()))
return parser.nextText();
}
return null;
}
}
<?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <getMobileCodeInfo xmlns="http://WebXml.com.cn/"> <mobileCode>#</mobileCode> <userID></userID> </getMobileCodeInfo> </soap12:Body> </soap12:Envelope>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有