Ana bilgisayar adı, aşağıdaki sözdizimiyle eşleşmelidir:
hostname = domainlabel [ "." ] | 1*( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
toplabel = alpha | alpha *( alphanum | "-" ) alphanum
Gördüğünüz gibi, sadece .ve -izin verilir, buna izin verilmez _.
Daha sonra //5-12-145-35_s-81:443buna izin verildiğini söylersiniz ve buna izin verilir, ancak ana bilgisayar adı için değil .
Bunun nasıl ortaya çıktığını görmek için:
URI uriBadHost = URI.create("//5-12-145-35_s-81:443");
System.out.println("uri = " + uriBadHost);
System.out.println(" authority = " + uriBadHost.getAuthority());
System.out.println(" host = " + uriBadHost.getHost());
System.out.println(" port = " + uriBadHost.getPort());
URI uriGoodHost = URI.create("//example.com:443");
System.out.println("uri = " + uriGoodHost);
System.out.println(" authority = " + uriGoodHost.getAuthority());
System.out.println(" host = " + uriGoodHost.getHost());
System.out.println(" port = " + uriGoodHost.getPort());
Çıktı
uri = //5-12-145-35_s-81:443
authority = 5-12-145-35_s-81:443
host = null
port = -1
uri = //example.com:443
authority = example.com:443
host = example.com
port = 443
Gördüğünüz gibi, authoritygeçerli bir ana bilgisayar adına sahip olduğunda ve hostve portayrıştırılır, ancak geçerli olmadığında, authorityserbest biçimli metin olarak ele alınır ve daha fazla ayrıştırılmaz.
GÜNCELLEME
Yorumdan:
System.out.println( new URI(null, null, "/5-12-145-35_s-81", 443, null, null, null))çıkışlar: /// 5-12-145-35_s-81: 443. Hostname olarak veriyorum
URIYapıcı Sen çağıran bir kolaylık yöntemdir ve basit bir tam URI dizesini oluşturur ve daha sonra bu ayrıştırır.
Geçmek "5-12-145-35_s-81", 443olur //5-12-145-35_s-81:443.
Geçmek "/5-12-145-35_s-81", 443olur ///5-12-145-35_s-81:443.
İlk olarak, bir ana bilgisayar ve bağlantı noktasıdır ve ayrıştırılamaz.
İkincisinde otorite bölümü boştur ve /5-12-145-35_s-81:443bir yoldur .
URI uri1 = new URI(null, null, "/5-12-145-35_s-81", 443, null, null, null);
System.out.println("uri = " + uri1);
System.out.println(" authority = " + uri1.getAuthority());
System.out.println(" host = " + uri1.getHost());
System.out.println(" port = " + uri1.getPort());
System.out.println(" path = " + uri1.getPath());
Çıktı
uri = ///5-12-145-35_s-81:443
authority = null
host = null
port = -1
path = /5-12-145-35_s-81:443