Nazwa hosta musi być zgodna z następującą składnią:
hostname = domainlabel [ "." ] | 1*( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
toplabel = alpha | alpha *( alphanum | "-" ) alphanum
Jak widać, tylko .i -są dozwolone, _nie jest.
Mówisz wtedy, że //5-12-145-35_s-81:443jest to dozwolone, ale nie w przypadku nazwy hosta .
Aby zobaczyć, jak to wygląda:
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());
Wynik
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
Jak widać, gdy authorityma poprawną nazwę hosta, hosti portsą analizowane, ale gdy nie są poprawne, authoritytraktowane jest jako dowolny tekst i nie jest dalej analizowane.
AKTUALIZACJA
Od komentarza:
System.out.println( new URI(null, null, "/5-12-145-35_s-81", 443, null, null, null))wyjścia: /// 5-12-145-35_s-81: 443. Podaję go jako nazwę hosta
URIKonstruktor Dzwonisz to metoda wygoda i prostota buduje pełny ciąg URI, a następnie analizuje to.
Przechodzenie "5-12-145-35_s-81", 443staje się //5-12-145-35_s-81:443.
Przechodzenie "/5-12-145-35_s-81", 443staje się ///5-12-145-35_s-81:443.
Po pierwsze, jest to host i port i nie można go parsować.
W drugiej części autorytet jest pusty i /5-12-145-35_s-81:443jest ścieżką .
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());
Wynik
uri = ///5-12-145-35_s-81:443
authority = null
host = null
port = -1
path = /5-12-145-35_s-81:443