1. 程式人生 > >通過淘寶介面獲取手機號碼歸屬地

通過淘寶介面獲取手機號碼歸屬地

介面地址:https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=
請求方式:get
示例程式碼:/// <summary>
/// 傳送HTTP請求
/// </summary>
/// <param name="url">請求的URL</param>
/// <param name="param">請求的引數</param>
/// <returns>請求結果</returns>
public static JsonModel Request(string url, string param)
{
string strURL = url + param;
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
request.Method = "GET";
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.Default);
while ((StrDate = Reader.ReadLine()) != null)
{
strValue += StrDate + "\r\n";
}
strValue = strValue.Replace("__GetZoneResult_ =", "");
JsonModel m = JsonConvert.DeserializeObject<JsonModel>(strValue);
return m;
}

返回資料:__GetZoneResult_ = {
mts:'',
province:'廣東',
catName:'中國聯通',
telString:'手機號',
areaVid:'',
ispVid:'',
carrier:'廣東聯通'
}

輔助類:`public class JsonModel
{
public string mts { get; set; }
public string province { get; set; }

    public string telString { get; set; }
}`