在java中获取URL的域名或IP与端口

package com.xxl.sso.sample;

import java.net.URI;
import java.net.URISyntaxException;

public class test {
    public static void main(String[] args) throws URISyntaxException {
        System.out.println(getIP(new URI("http://www.baidu.com/system/verList")));
        System.out.println(getIP(new URI("http://10.10.14.199:8080/dsideal_yy/")));
        System.out.println(getIP(new URI("http://127.0.0.1:9040/system/verList?loginName=1&password=AD07FB25AA2D3A9F96EE12F25E0BE902")));
    }

    private static URI getIP(URI uri) {
        URI effectiveURI = null;
        try {
            effectiveURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
        } catch (Throwable var4) {
            effectiveURI = null;
        }
        return effectiveURI;
    }

}
原文地址:https://www.cnblogs.com/littlehb/p/9967900.html