URL模块

作者: 迷人的洋葱葱 | 来源:发表于2017-10-06 16:04 被阅读0次

    一、URL模块

    -参数request:http.IncomingMessage的一个实例,通过它可以获取到这次请求的一些信息。
    --url:请求的地址。
    发送请求的地址,也叫访问路径
    ?后面的部分叫做查询字符串(query string)。

    var http=require('http');
    var url=require('url');
    var server=http.createServer();
    server.on('request',function(req,res){
    var urlStr=url.parse(req.url);
    });
    
    var urlStr=url.parse('http://www.baidu.com:8080/a/index.html?b=2#p=1');
    

    parse()方法可以将url地址解析为一个包含url信息的对象。
    该对象的部分属性如下:
    protocol:'http:',
    host:'www.baidu.com:8080',
    port:'8080',
    hostname:'www.baidu.com',
    hash:'#p=1',
    search:'?b=2',
    query:'b=2',
    pathname:'/a/index.html',
    path:'/a/index.html?b=2',
    href:'http://www.baidu.com:8080/a/index.html?b=2#p=1'

    相关文章

      网友评论

          本文标题:URL模块

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