URL组成:
protocol://host:port/path?query
从URL中拿到host:
public static String getHostFromURL(String url){ if(url==null) return null; //remove 'http(s)://' int index=url.indexOf("//"); if(index>=0) url=url.substring(index+"//".length()); //remove path of URL index=url.indexOf("/"); if(index>=0) url=url.substring(0,index); return url; }