public class Main {
public static void main(String[] args) throws Exception {
URL url = new URL(https://www.example.com/path/to/page?query=1);
String domain = url.getHost();
System.out.println(domain); // 输出: www.example.com
}
}
在 C中,可以使用 `System.Uri` 类:
csharp
using System;
class Program
{
static void Main()
{
Uri uri = new Uri(https://www.example.com/path/to/page?query=1);
string domain = uri.Host;
Console.WriteLine(domain); // 输出: www.example.com
}
}