调用百度 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