c# 手机号码归属地查询
此方法不是使用WebService。
而是直接使用提供号码归属地查询的网站,然后输入号码返回结果页面的办法,再用正则表达式提取需要的信息
[当然也可以使用WebService http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo 提供的 服务来查询,可是这个又限制使用的次数]
引用:
using System.Text.RegularExpressions;
using System.Net;
而是直接使用提供号码归属地查询的网站,然后输入号码返回结果页面的办法,再用正则表达式提取需要的信息
[当然也可以使用WebService http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo 提供的 服务来查询,可是这个又限制使用的次数]
引用:
using System.Text.RegularExpressions;
using System.Net;
private void button1_Click(object sender, EventArgs e)
{
string phoneNum = tbPhoneNum.Text;
try
{
//web客户端
WebClient webclient = new WebClient();
//下载数据
string str_ = webclient.DownloadString("http://www.ip138.com:8080/search.asp?mobile=" + phoneNum + "&action=mobile");
//正则
string str_regex = "><!-- <td></td> -->.*</TD>";
//忽略大小写
Regex regex = new Regex(str_regex, RegexOptions.IgnoreCase);
//开始匹配
MatchCollection matchCollection = regex.Matches(str_);
txtAddress.Text = "卡归属地:" + matchCollection[0].Value.Replace("><!-- <td></td> -->","").Replace("</TD>","");
txtType.Text = "卡类型:" + matchCollection[1].Value.Replace("><!-- <td></td> -->", "").Replace("</TD>", "");
}
catch (Exception ex) { }
}
...全文


