Public classiphttpclient:basehttpclient {PrivateString AppKey; Private Const stringHost_path ="Http://apis.baidu.com/apistore/iplookupservice/iplookup"; Publiciphttpclient () { This. AppKey = Basehelper.getvalue ("Baiduappkey"); } /// <summary> ///HTTP Authentication/// </summary> /// <returns></returns> Public Overridedictionary<string,string>Authorization () {return Newdictionary<string,string> {{"Apikey", This. AppKey}}; } /// <summary> ///returns the location information for the current IP/// </summary> /// <param name= "IP" ></param> /// <returns></returns> PublicResultdto getipaddress (stringIP) { varReqparams =NewDictionary<string, string> { {"IP", IP}}; vardata = This. SendRequest (Method.get, Host_path, This. Buildquerystr (Reqparams)); varresult=Jsonhelper.toobject (data.info.ToString ()); if(Data.status && Convert.ToInt32 (result["Errnum"]) ==0) { varAddress = Jsonhelper.toobject (result["Retdata"]. ToString ()); returnWebapi.success (address["Country"]. ToString () + address["Province"] + address[" City"]); } returnWebapi.error (Data.info); } }
C # Application of HttpClient (i): Obtaining geo-location information on IP