展会信息港展会大全

asp.net 手机号码所在地查询实现代码
来源:互联网   发布日期:2016-01-27 15:28:23   浏览:2479次  

导读:用浏览器打开手机号码查询的网站,同以上步骤找到他调用的地址,最后编写代码如下:代码如下using System;using System Windows Forms;using System Xml;namespace HnVote{ public partial class Mobile ...

用浏览器打开手机号码查询的网站,同以上步骤找到他调用的地址,最后编写代码如下:

代码如下

using System;

using System.Windows.Forms;

using System.Xml;

namespace HnVote

{

public partial class Mobile : Form

{

public Mobile()

{

InitializeComponent();

}

privatestatic 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);

}

}

}

}

界面:

赞助本站

人工智能实验室

相关热词: 手机号码 所在地 查询 net

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港