工作生活

url

2019-07-03  本文已影响0人  kanaSki

url:统一资源定位器
互联网三大基石:url、html、http

    public static void main(String[] args) throws MalformedURLException {
        URL url = new URL("http://www.baidu.com:80/index.html?uname=123&age=8#a");
        // 获取四个值
        String protocol = url.getProtocol();
        System.out.println("协议" + protocol);
        String host = url.getHost();
        System.out.println("域名ip" + host);
        int port = url.getPort();
        System.out.println("端口" + port);
        String file = url.getFile();    // 包含请求参数,不包含锚点
        System.out.println("请求资源" + file);
        String path = url.getPath();    // index.html
        System.out.println("请求资源" + path);
        String query = url.getQuery();
        System.out.println("参数" + query);
        String ref = url.getRef();
        System.out.println("锚点" + ref);
    }
上一篇 下一篇

猜你喜欢

热点阅读