A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 何家旺 黑马粉丝团   /  2013-8-20 22:43  /  6484 人查看  /  89 人回复  /   4 人收藏 转载请遵从CC协议 禁止商业使用本文

如题,实现手机号码归属地查询!
  1. public class Mobile {
  2.         /**
  3.          * 获得soap请求
  4.          * @param mobileCode
  5.          * @return
  6.          */
  7.         private static String getSoapRequest(String mobileCode){
  8.                 StringBuilder sb = new StringBuilder();
  9.                 sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+"\n"
  10.                                 +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+" "
  11.                                 +"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""+" "
  12.                                 +"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+"\n"
  13.                                 +"<soap:Body>"+"\n"
  14.                                 +"<getMobileCodeInfo"+" "+"xmlns=\"http://WebXml.com.cn/\">"+"\n"
  15.                                 +"<mobileCode>"+mobileCode+"</mobileCode>"+"\n"
  16.                                 +"<userID></userID>"+"\n"
  17.                                 +"</getMobileCodeInfo>"+"\n"
  18.                                 +"</soap:Body>"+"\n"
  19.                                 +"</soap:Envelope>"
  20.                                 );
  21.                 return sb.toString();
  22.         }
  23.         /**
  24.          * 发送soap请求到服务器,并接受返回数据
  25.          * @param mobileCode
  26.          * @return
  27.          */
  28.         private static InputStream getSoapInputStream(String mobileCode){
  29.                 try {
  30.                         String soap = getSoapRequest(mobileCode);
  31.                         if(soap == null)
  32.                                 return null;
  33.                         URL url = new URL("http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx");
  34.                         URLConnection conn = url.openConnection();
  35.                         conn.setUseCaches(false);
  36.                         conn.setDoInput(true);
  37.                         conn.setDoOutput(true);
  38.                         
  39.                         conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
  40.                         conn.setRequestProperty("Content-Length", Integer.toString(soap.length()));
  41.                         conn.setRequestProperty("SOAPAction", "http://WebXml.com.cn/getMobileCodeInfo");
  42.                         
  43.                         OutputStream os = conn.getOutputStream();
  44.                         OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
  45.                         osw.write(soap);
  46.                         osw.flush();
  47.                         osw.close();
  48.                         
  49.                         InputStream is = conn.getInputStream();
  50.                         return is;
  51.                 } catch (Exception e) {
  52.                         e.printStackTrace();
  53.                         return null;
  54.                 }
  55.         }
  56.         
复制代码
游客,如果您要查看本帖隐藏内容请回复

89 个回复

正序浏览
多谢分享,好人一生平安
回复 使用道具 举报
回复 使用道具 举报
棒棒的 赞赞赞赞
回复 使用道具 举报
支持一下,赞一个
回复 使用道具 举报
回复 使用道具 举报
实现手机号码归属地查询
回复 使用道具 举报
回复 使用道具 举报
学习使我快乐
回复 使用道具 举报
支持下楼主
回复 使用道具 举报
支持支持
回复 使用道具 举报
66666666666
回复 使用道具 举报
还可以这么玩????
回复 使用道具 举报
603291569 来自手机 初级黑马 2017-11-18 09:25:48
149#
66666666666
回复 使用道具 举报
@aa 来自手机 初级黑马 2017-11-17 11:16:10
148#
还会让自己成为你生命之间
回复 使用道具 举报
6666666666666666
回复 使用道具 举报

学习学习!
回复 使用道具 举报
Sakua 初级黑马 2017-10-26 09:11:08
145#

感谢分享
回复 使用道具 举报
llrs 初级黑马 2017-10-23 13:47:54
144#
好东西当然要学习了。。
来自宇宙超级黑马专属安卓客户端来自宇宙超级黑马专属安卓客户端
回复 使用道具 举报
下次VS的方法
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马