URI - getHost returns null. Why?

前端 未结 5 2028
春和景丽
春和景丽 2021-01-04 03:36

Why is the 1st one returning null, while the 2nd one is returning mail.yahoo.com?

Isn\'t this weird? If not, what\'s the logic behind this

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 04:32

    It's because of underscore in base uri. Just Remove underscore to check that out.It's working.

    Like given below :

    public static void main(String[] args) throws Exception {
    java.net.URI uri = new java.net.URI("http://brokenarrow.huntingtonhelps.com");
    String host = uri.getHost();
    System.out.println("Host = [" + host + "].");
    
    uri = new java.net.URI("http://mail.yahoo.com");
    host = uri.getHost();
    System.out.println("Host = [" + host + "].");
    

    }

提交回复
热议问题