C#使用HttpClient获取IP地址位置和网络信息
C# 全选
/// <summary>
/// C#使用HttpClient获取IP地址位置和网络信息, 如:广东省珠海市 电信
/// </summary>
/// <param name="ipAddress"></param>
/// <returns></returns>
private static string GetIpLocationFromPCOnline(string ipAddress)
{
string ipLocation = "未知";
try
{
var res = "";
using (var client = new HttpClient())
{
var URL = "http://whois.pconline.com.cn/ip.jsp?ip=" + ipAddress;
var response = client.GetAsync(URL).GetAwaiter().GetResult();
response.EnsureSuccessStatusCode();
res = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}
if (!string.IsNullOrEmpty(res))
{
ipLocation = res.Trim();
}
}
catch
{
ipLocation = "未知";
}
return ipLocation;
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网