在
MSDN,它提到GetHostByName已过时.替换是GetHostEntry.它们有什么区别?
解决方法
看起来像GetHostEntry做了更多的错误检查,也支持
Network Tracing
GetHostByName已解压缩:
public static IPHostEntry GetHostByName(string hostName) { if (hostName == null) throw new ArgumentNullException("hostName"); Dns.s_DnsPermission.Demand(); IPAddress address; if (IPAddress.TryParse(hostName,out address)) return Dns.GetUnresolveAnswer(address); else return Dns.InternalGetHostByName(hostName,false); }
GetHostEntry已解压缩:
public static IPHostEntry GetHostEntry(string hostNameOrAddress) { if (Logging.On) Logging.Enter(Logging.Sockets,"DNS","GetHostEntry",hostNameOrAddress); Dns.s_DnsPermission.Demand(); if (hostNameOrAddress == null) throw new ArgumentNullException("hostNameOrAddress"); IPAddress address; IPHostEntry ipHostEntry; if (IPAddress.TryParse(hostNameOrAddress,out address)) { if (((object) address).Equals((object) IPAddress.Any) || ((object) address).Equals((object) IPAddress.IPv6Any)) throw new ArgumentException(SR.GetString("net_invalid_ip_addr"),"hostNameOrAddress"); ipHostEntry = Dns.InternalGetHostByAddress(address,true); } else ipHostEntry = Dns.InternalGetHostByName(hostNameOrAddress,true); if (Logging.On) Logging.Exit(Logging.Sockets,(object) ipHostEntry); return ipHostEntry; }