url

作者: kanaSki | 来源:发表于2019-07-03 19:56 被阅读0次

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);
    }

相关文章

网友评论

    本文标题:url

    本文链接:https://www.haomeiwen.com/subject/msthhctx.html