码迷,mamicode.com
首页 > 移动开发 > 详细

.net手机号码归属地查询

时间:2016-05-03 12:45:41      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

 

调用百度 api

http://apistore.baidu.com/apiworks/servicedetail/117.html

 

贴上代码

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

 

/// <summary>
/// 发送HTTP请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="param">请求的参数</param>
/// <returns>请求结果</returns>
public static string requests(string url, string param)
{
string strURL = url + ‘?‘ + param;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "GET";
// 添加header
request.Headers.Add("apikey", "自己申请一个");
System.Net.HttpWebResponse response;
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
string StrDate = "";
string strValue = "";
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate + "\r\n";
}
return strValue;
}

 

string url = "http://apis.baidu.com/apistore/mobilephoneservice/mobilephone";
string param = "tel=15828343985";
string result = requests(url, param);

JObject jo = JObject.Parse(result);
jo["retData"]["province"].ToString();

 

NewtonJson.dll 下载

http://files.cnblogs.com/files/dodui/NewtonJson.rar

.net手机号码归属地查询

标签:

原文地址:http://www.cnblogs.com/dodui/p/5454443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!