程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> asp.net 手機號碼所在地查詢實現代碼

asp.net 手機號碼所在地查詢實現代碼

編輯:關於ASP.NET

    用浏覽器打開手機號碼查詢的網站,同以上步驟找到他調用的地址,最後編寫代碼如下:

     代碼如下
    using System;
    using System.Windows.Forms;
    using System.Xml;
    namespace HnVote
    {
        public partial class Mobile : Form
        {
            public Mobile()
            {
                InitializeComponent();
            }
            private  static string[] GetMobileInfo(string number)
            {
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load("http://api.showji.com/Locating/default.aspx?m=" + number);
                    XmlNamespaceManager cx = new XmlNamespaceManager(xmlDocument.NameTable);
                    cx.AddNamespace("content", "http://api.showji.com/Locating/");
                    XmlNodeList nodes = xmlDocument.SelectNodes 

                ("//content:QueryResult|//content:Mobile|//content:Province|//content:City|//

                content:Corp|//content:Card|//content:AreaCode|//content:PostCode", cx);
                    if (nodes.Count == 8)
                    {
                        if ("True".Equals(nodes[1].InnerText))
                        {
                            return new string[]
                                       {
                                           nodes[0].InnerText, nodes[2].InnerText, nodes[3].InnerText, nodes[4].InnerText,
                                           nodes[5].InnerText, nodes[6].InnerText + nodes[7].InnerText
                                       };
                        }
                    }
                    return new string[] { "false" };
                }
                catch (Exception)
                {
                    return new string[] { "false" };
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    string[] num = GetMobileInfo(textBox1.Text);
                    MessageBox.Show("所查號碼:" + num[0] + "n歸屬省份:" + num[1] + "n歸屬城市:" + num[2] + "n城市區號:" + num[3] + "n城市郵編:" +
                                    num[4] + "n卡 類 型:" + num[5], "查詢結果", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message,"錯誤提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                }
            }
            private void textBox1_KeyDown(object sender, KeyEventArgs e)
            {
                if(e.KeyCode==Keys.Enter)
                {
                    button1_Click(sender,e);
                }
            }
        }
    }  
     

    界面:

    asp.net 手機號碼所在地查詢實現代碼 三聯


     

     

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved