C# Uri.CheckHostName(String) 方法不起作用?
C# Uri.CheckHostName(String) Method not working?
有人能解释一下为什么我在 c# 中使用 Uri.CheckHostName(String) 方法时出现这种行为吗:
Console.WriteLine(Uri.CheckHostName("10"));
输出:IPv4
Console.WriteLine(Uri.CheckHostName("F"));
输出:DNS
如您所见,它们的 IPv4 或 DNS 值无效...
让我们看看 code called by Uri.CheckHostName,其中包括这条评论:
// Determines whether a string is a valid domain name label. In keeping
// with RFC 1123, section 2.1, the requirement that the first character
// of a label be alphabetic is dropped. Therefore, Domain names are
// formed as:
//
// <label> -> <alphanum> [<alphanum> | <hyphen> | <underscore>] * 62
强调这一行:
the requirement that the first character of a [DNS] label be
alphabetic is dropped.
该方法还调用此 code 来检查有效字符。
简而言之,在我看来这是设计使然。
有人能解释一下为什么我在 c# 中使用 Uri.CheckHostName(String) 方法时出现这种行为吗:
Console.WriteLine(Uri.CheckHostName("10"));
输出:IPv4
Console.WriteLine(Uri.CheckHostName("F"));
输出:DNS
如您所见,它们的 IPv4 或 DNS 值无效...
让我们看看 code called by Uri.CheckHostName,其中包括这条评论:
// Determines whether a string is a valid domain name label. In keeping
// with RFC 1123, section 2.1, the requirement that the first character
// of a label be alphabetic is dropped. Therefore, Domain names are
// formed as:
//
// <label> -> <alphanum> [<alphanum> | <hyphen> | <underscore>] * 62
强调这一行:
the requirement that the first character of a [DNS] label be alphabetic is dropped.
该方法还调用此 code 来检查有效字符。
简而言之,在我看来这是设计使然。