http://www.webxml.com.cn/zh_cn/index.aspx
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo
//soap 简单对象访问协议.
通过一个xml协议,让我们可以访问某个对象里面的方法.
一个xml文件发给服务器.
用post请求发送.因为文件比较多.
客户端最主要的的任务就是1解析本地xml文件,2然后发送给服务器.3获得服务器返回的信息.
public void testGetAddress() throws Exception{
URL url = new URL("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("POST");
//得到xml文件,转为流.
InputStream is = getClass().getClassLoader().getResourceAsStream("data.xml");
//将流转为byte数组.
byte [] data = StreamTool.getBytes(is);
//得到xml信息.
String str = new String(data);
//将占位符里面的东西换位手机号码
//content.这就是向服务器发送的数据.
String content = str.replace("$mobile", "13512345678");
System.out.println(content);
//
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
conn.setRequestProperty("Content-Length", content.length()+"");
//向服务器设置发送数据.
conn.getOutputStream().write(content.getBytes());
//得到返回的xml文件.
InputStream response = conn.getInputStream();
System.out.println( new String( StreamTool.getBytes(response)));
在src下,data.xml文件.
<pre class="html" name="code"><?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>$mobile</mobileCode>
<userID></userID>
</getMobileCodeInfo>
</soap12:Body>
</soap12:Envelope>