zoukankan      html  css  js  c++  java
  • C#关于HttpClient的应用(一):获取IP所在的地理位置信息

        public class IpHttpClient:BaseHttpClient
        {
            private String appKey;
            private const string HOST_PATH = "http://apis.baidu.com/apistore/iplookupservice/iplookup";
    
            public IpHttpClient()
            {
                this.appKey = BaseHelper.GetValue("BaiduAppKey");
            }
    
            /// <summary>
            /// HTTP 验证
            /// </summary>
            /// <returns></returns>
            public override Dictionary<string, string> Authorization()
            {
                return new Dictionary<string, string> {{"apikey", this.appKey}};
            }
    
            /// <summary>
            /// 返回当前Ip所在的地理位置信息
            /// </summary>
            /// <param name="ip"></param>
            /// <returns></returns>
            public ResultDTO GetIpAddress(string ip)
            {
                var reqParams = new Dictionary<String, String>
                {
                    {"ip", ip}
                };
    
                var data = this.SendRequest(Method.Get, HOST_PATH, this.BuildQueryStr(reqParams));
                var result= JsonHelper.ToObject(data.info.ToString());
                if (data.status && Convert.ToInt32(result["errNum"]) == 0)
                {
                    var address = JsonHelper.ToObject(result["retData"].ToString());
                    return WebApi.Success(address["country"].ToString() + address["province"] + address["city"]);
                }
                return WebApi.Error(data.info);
            }
        }
  • 相关阅读:
    js里面的 InttoStr 和 StrtoInt
    预编译知识 (转载记录)
    C语言操作内存
    C语言操作文件
    C语言
    如何调试shell脚本
    设计模式-装饰者模式
    自己动手制作一个模版解析
    设计模式-单例模式
    http中关于缓存的那些header信息
  • 原文地址:https://www.cnblogs.com/xuhang/p/5204965.html
Copyright © 2011-2022 走看看