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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 何家旺 黑马粉丝团   /  2013-8-20 22:43  /  6400 人查看  /  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 个回复

倒序浏览
支持一下楼主
回复 使用道具 举报
学习学习!
回复 使用道具 举报
学习学习!
回复 使用道具 举报
学习了{:soso_e128:}{:soso_e181:}
回复 使用道具 举报
楼主好人
回复 使用道具 举报
傅宇 中级黑马 2013-9-13 22:36:50
7#
不错哟。
回复 使用道具 举报
{:soso_e100:}
回复 使用道具 举报
下载查看
回复 使用道具 举报
shoujiaole henbucuo
回复 使用道具 举报
学习了  :)
回复 使用道具 举报
不愧是乔帮主
回复 使用道具 举报
谢谢lz啊
回复 使用道具 举报
噩噩噩噩噩噩噩噩噩噩噩噩噩噩噩噩噩噩噩
回复 使用道具 举报
风乐 中级黑马 2013-12-20 16:02:53
15#
WebService 实现手机号码归属地查询
回复 使用道具 举报
chensc 金牌黑马 2013-12-21 15:08:04
16#
学习学习!
回复 使用道具 举报
chensc 金牌黑马 2013-12-26 08:18:27
17#
学习学习!
回复 使用道具 举报
学习学习!
回复 使用道具 举报
学习了  
回复 使用道具 举报

支持一下! 不错!!
回复 使用道具 举报
12345下一页
您需要登录后才可以回帖 登录 | 加入黑马