美文网首页
node的url模块

node的url模块

作者: 浮若年华_7a56 | 来源:发表于2022-06-30 09:59 被阅读0次

1.url.parse(要解析的url地址,是否将query解析为对象格式,在没有协议的情况下,是否解析域名)

url.parse("http://user.com:8080/p/a/t/h?query=string#hash");
/*
返回值:
{
  protocol: 'http:',
  slashes: true,
  auth: 'user:pass',
  host: 'host.com:8080',
  port: '8080',
  hostname: 'host.com',
  hash: '#hash',
  search: '?query=string',
  query: 'query=string',
  pathname: '/p/a/t/h',
  path: '/p/a/t/h?query=string',
  href: 'http://user.com:8080/p/a/t/h?query=string#hash'
}

没有设置第二个参数为true时,query属性为一个字符串类型
*/
2.url.format(对象) 把url解析成的对象还原成字符串

url.format({
  protocol:"http:",
  host:"182.163.0.0:80",
  port:"80"
});
/*
返回值:
'http://182.163.0.0:80'
*/

3.url.resolve(from, to)将两段url解析成一个url地址

url.resolve('http://www.baidu112.com','/index.html');
/*
返回值:
'http://www.baidu112.com/index.html'
*/

相关文章

  • 兄弟会8.9号笔记

    node.js模块学习 http 模块 fs 模块 url 模块 http 模块 HTTP http.STA...

  • 高明1024学习笔记

    node.js的URL模块学习 URL统一资源定位符 URL中文文档:协议+域名/IP地址 该模块包含用以 URL...

  • Node的Url模块

    Url 模块 Node的url模块主要提供一些实用的函数来进行url的处理和分析。 url字符串和url对象 ur...

  • Node url模块

    url Nodejs的url模块只要提供一些实用函数,用于URL的处理和解析。在Nodejs中可以直接引用url模...

  • node的url模块

    1.url.parse(要解析的url地址,是否将query解析为对象格式,在没有协议的情况下,是否解析域名) 没...

  • Node.js_常用的模块(四)

    Node.js_常用的模块(四) 主要介绍几个模块:url / querystring / path / proc...

  • NodeJs学习3--API

    url node下打印url 引入url模块 parse方法 将url解析成对象,parse方法原型: 可传递三个...

  • 利用node实现get请求数据读写、处理post请求参数以及使用

    一般node中去获取拼接在url的get参数,需要利用node的内置模块中的queryString以及url这两个...

  • node中URL模块

    node中的URL模块,有两个版本, 一个是Node.js遗留的特有的API 保留的原因:虽然Node.js遗留的...

  • node之URL模块

    WHATWG URL的origin属性包括protocol和host,但不包含username和password ...

网友评论

      本文标题:node的url模块

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