日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

调用webservice查询手机号码归属地信息

發布時間:2025/4/16 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 调用webservice查询手机号码归属地信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Web Services是由企業發布的完成其特定商務需求的在線應用服務,其他公司或應用軟件能夠通過Internet來訪問并使用這項在線服務。在這里我們使用soap協議往webservice發送信息,然后得到webservice服務器返回過來的信息,以此來查詢手機號碼的歸屬地信息。

Web Services有很多服務提供商,在這里我們使用www.webxml.com.cn的,如圖:

點擊進去,我們可以看到soap協議定義的內容。

接下來就是編寫代碼了。

package cn.mzba.service; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import org.xmlpull.v1.XmlPullParser; import android.util.Xml; public class MobileService { public static String findAddress(String mobile) throws Exception { InputStream is = MobileService.class.getClassLoader() .getResourceAsStream("mobilesoap.xml"); byte[] data = StreamTool.readStream(is); String xml = new String(data, "UTF-8"); String soap = xml.replaceAll("\\$mobile", mobile); byte[] result = soap.getBytes("UTF-8"); String path = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"; URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setConnectTimeout(5 * 1000); conn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8"); conn.setRequestProperty("Content-Length", String.valueOf(result.length)); OutputStream os = conn.getOutputStream(); os.write(result); os.flush(); os.close(); InputStream isSocp = conn.getInputStream(); return parse(isSocp); } public static String parse(InputStream is) throws Exception { XmlPullParser parser = Xml.newPullParser(); parser.setInput(is, "UTF-8"); int event = parser.getEventType(); while (event != XmlPullParser.END_DOCUMENT) { switch (event) { case XmlPullParser.START_TAG: if ("getMobileCodeInfoResult".equals(parser.getName())) { return parser.nextText(); } break; } event = parser.next(); } return null; } }





package cn.mzba.service; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class StreamTool { /** * 讀取輸入流數據 *? * @param is * @return * @throws Exception */ public static byte[] readStream(InputStream is) throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int len = 0; while ((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } is.close(); return os.toByteArray(); } }

轉載于:https://www.cnblogs.com/xiaochao1234/p/3799863.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的调用webservice查询手机号码归属地信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。