zoukankan      html  css  js  c++  java
  • .net*归属地查询

    调用百度 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 + " ";
    }
    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

  • 相关阅读:
    Django之DB数据库优化
    whatweb运行流程详解,适用于小白
    阿里云部署Django详细过程
    web指纹识别技术
    whatweb运行原理及各文件的作用详解
    Ruby种的特殊变量
    Ruby正则练习面试题
    centos7安装升级Ruby
    Ruby中的<<和>>的作用详解
    git操作指令合集
  • 原文地址:https://www.cnblogs.com/dodui/p/5454443.html
Copyright © 2011-2022 走看看