📜  C#| Uri.CheckHostName(String)方法

📅  最后修改于: 2021-05-29 14:49:26             🧑  作者: Mango

Uri.CheckHostName(String)方法用于确定指定的主机名是否为有效的DNS名称。

下面的程序说明了Uri.CheckHostName()方法的用法:

范例1:

// C# program to demonstrate the
// Uri.CheckHostName(string) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing uri
        string uri = "www.geeksforgeeks.org";
  
        // using CheckHostName() method
        UriHostNameType value = Uri.CheckHostName(uri);
  
        // Displaying the result
        Console.WriteLine("Host type is: {0}", value);
    }
}
输出:
Host type is: Dns

范例2:

// C# program to demonstrate the
// Uri.CheckHostName(string) Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and initializing uri
        string uri = "http:// localhost:3000";
  
        // using CheckHostName() method
        UriHostNameType value = Uri.CheckHostName(uri);
  
        // Displaying the result
        Console.WriteLine("Host type is: {0}", value);
    }
}
输出:
Host type is: Unknown

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.uri.checkhostname?view=netstandard-2.1