El nombre del host debe coincidir con la siguiente sintaxis:
hostname = domainlabel [ "." ] | 1*( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
toplabel = alpha | alpha *( alphanum | "-" ) alphanum
Como puede ver, solo .y -están permitidos, _no lo está.
Luego dice que //5-12-145-35_s-81:443está permitido, y lo está, pero no para el nombre de host .
Para ver cómo funciona:
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());
Salida
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
Como puede ver, cuando authoritytiene un nombre de host válido, se analiza el hosty port, pero cuando no es válido, authorityse trata como texto de forma libre y no se analiza más.
ACTUALIZAR
De comentario:
System.out.println( new URI(null, null, "/5-12-145-35_s-81", 443, null, null, null))salidas: /// 5-12-145-35_s-81: 443. Lo estoy dando como nombre de host
El URIconstructor al que está llamando es un método conveniente, y simplemente crea una cadena de URI completa y luego la analiza.
Pasar se "5-12-145-35_s-81", 443convierte //5-12-145-35_s-81:443.
Pasar se "/5-12-145-35_s-81", 443convierte ///5-12-145-35_s-81:443.
En el primero, es un host y un puerto , y no se analiza.
En el segundo, la parte de autoridad está vacía y /5-12-145-35_s-81:443es un camino .
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());
Salida
uri = ///5-12-145-35_s-81:443
authority = null
host = null
port = -1
path = /5-12-145-35_s-81:443