android擷取手機歸屬地

來源:互聯網
上載者:User

一個需求需要擷取手機歸屬地,在網上看了好多代碼試了好多都不行,都是到conn.setrequestmethod("post")就卡住了,也沒有去研究具體是什麼問題,後來看了擷取手機歸屬地的webservice,地址:

http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl

就自己寫了,直接使用調用webservice的方法去實現,結果是可以行的;還顯得更簡單,,但不懂有沒有弊端。

以下是代碼

public class MobileService

{

    //NameSpace命名空間

    public final static String NameSpace = "http://WebXml.com.cn/";

    //SoapOption命名空間+方法名

    public final static String SoapOption = "http://WebXml.com.cn/getMobileCodeInfo";

    //MethodName將要調用的方法名

    public final static String MethodName = "getMobileCodeInfo";

    //WebServiceURL WebService地址

    public final static String WebServiceURL = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";

    //定義一個SoapObject對象

    public SoapObject request = null;

   

    public String GetMobileAddress(String phoneNO)

    {

      request = new SoapObject(NameSpace, MethodName);

      request.addProperty("mobileCode", phoneNO);//預存程序方法參數,參數名與webservice的參數名順序都需要一致

      request.addProperty("userID", "");

      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

      envelope.bodyOut = request;

      envelope.dotNet = true;//指定為調用.net

      HttpTransportSE ht = new HttpTransportSE(WebServiceURL);

      try

      {

        ht.call(SoapOption, envelope);

      }

      catch (Exception e)

      {

        e.printStackTrace();

      }

      //擷取資料

      try

      {

            Object result= (Object)envelope.getResponse();

            String str=result.toString();

            return str;//結果

      }

      catch (SoapFault e)

      {

           return null;

      }

    }

}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.