호스트 이름은 다음 구문과 일치해야합니다.
hostname = domainlabel [ "." ] | 1*( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
toplabel = alpha | alpha *( alphanum | "-" ) alphanum
당신이 볼 수 있듯이, 단지 .와 -, 허용 _되지 않습니다.
그런 다음 //5-12-145-35_s-81:443허용되지만 호스트 이름 에는 해당되지 않습니다 .
어떻게 진행되는지 확인하려면 :
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());
산출
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
보다시피, authority호스트 이름이 유효한 경우 host및 port구문 분석되지만 유효하지 않은 경우 authority자유 형식 텍스트로 처리되며 더 이상 구문 분석되지 않습니다.
최신 정보
의견에서 :
System.out.println( new URI(null, null, "/5-12-145-35_s-81", 443, null, null, null))출력 : /// 5-12-145-35_s-81 : 443. 호스트 이름으로 제공하고 있습니다
URI호출 하는 생성자는 편리한 메소드이며 전체 URI 문자열을 간단하게 빌드 한 다음 구문 분석합니다.
합격 "5-12-145-35_s-81", 443이됩니다 //5-12-145-35_s-81:443.
합격 "/5-12-145-35_s-81", 443이됩니다 ///5-12-145-35_s-81:443.
첫 번째로 호스트 및 포트 이며 구문 분석에 실패합니다.
두 번째로 권한 부분은 비어 /5-12-145-35_s-81:443있으며 경로 입니다.
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());
산출
uri = ///5-12-145-35_s-81:443
authority = null
host = null
port = -1
path = /5-12-145-35_s-81:443