样例:
static void Main(string[] args)
{
//http://pv.sohu.com/cityjson?ie=utf-8
//http://ip-api.com/json/115.191.200.34?lang=zh-CN
string Content ="";
string ip = "114.114.114.114";
string url = "http://ip-api.com/json/"+ip+"?lang=zh-CN";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader readStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
while (!readStream.EndOfStream)
{
Content += readStream.ReadLine();
}
}
IPTokenModel apiResult = JsonConvert.DeserializeObject<IPTokenModel>(Content);
Console.WriteLine(apiResult.query);
Console.WriteLine(apiResult.country);
Console.WriteLine(apiResult.regionName);
Console.WriteLine(apiResult.city);
Console.WriteLine(apiResult.status);
Console.ReadLine();
}
IPTokenModel.cs:
public class IPTokenModel
{
public string status { get; set; }
public string country { get; set; }
public string regionName { get; set; }
public string city { get; set; }
public string query { get; set; }
}
Today's comments have reached the limit. If you want to comment, please wait until tomorrow (UTC-Time).
There is 20h00m32s left until you can comment.