嗨 我有一個需要從URL中提取IP。下面的代碼是工作在一個案例:GetHostByName錯誤與http鏈接獲取IP地址
string str2 = "www.google.com";
IPHostEntry ip = Dns.GetHostByName(str2);
IPAddress [] IpA = ip.AddressList;
for (int i = 0; i < IpA.Length; i++)
{
Console.WriteLine ("IP Address {0}: {1} ", i, IpA[i].ToString());
}
但是,如果改變URL作爲
string str2 = "http://google.com";
GetHostByName
拋出異常。
我應該在哪種情況下使用哪種方法?
取決於我得到的答案。 – CrazyC 2011-04-22 09:44:14