Node.js中的URL模块
来源:互联网 发布:linux权限表示 编辑:程序博客网 时间:2024/06/07 10:26
URL模块简介
该模块包含用以 URL 解析的实用函数
//调用URL模块var url = require('url')
函数
url.parse(urlStr[, parseQueryString][, slashesDenoteHost])
输入 URL 字符串,返回一个对象
将第二个参数设置为 true 则使用 querystring 模块来解析 URL 中的查询字符串部分,默认为 false
将第三个参数设置为 true 来把诸如 //foo/bar 这样的URL解析为 { host: ‘foo’, pathname: ‘/bar’ } 而不是 { pathname: ‘//foo/bar’ }。 默认为 false
var url = require('url')var href = 'http://user:pass@host.com:8080/p/a/t/h?query=string#hash'console.log(url.parse(href))Url { 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:pass@host.com:8080/p/a/t/h?query=string#hash' }
href: 所解析的完整原始 URL。协议名和主机名都已转为小写
protocol: 请求协议,小写
host: URL主机名已全部转换成小写, 包括端口信息
auth:URL中身份验证信息部分
hostname:主机的主机名部分, 已转换成小写
port: 主机的端口号部分
pathname: URL的路径部分,位于主机名之后请求查询之前
search: URL 的“查询字符串”部分,包括开头的问号
path: pathname 和 search 连在一起
query: 查询字符串中的参数部分(问号后面部分字符串)
hash: URL 的 “#” 后面部分(包括 # 符号)
url.format(urlObj)
输入一个 URL 对象,返回格式化后的 URL 字符串
url.resolve(from, to)
给定一个基URL路径,和一个href URL路径,并且象浏览器那样处理他们可以带上锚点
url.resolve('/one/two/three', 'four') // '/one/two/four'url.resolve('http://example.com/', '/one') // 'http://example.com/one'url.resolve('http://example.com/one', '/two') // 'http://example.com/two'
0 0
- Node.js中的URL模块
- Node.js URL模块
- node.js url模块
- Node.js url模块
- Node.Js url模块详解
- Node.js中的模块
- Node.js 中的模块
- Node.js中的模块
- url及node.js url模块随笔
- C# Url操作类封装、仿Node.Js中的Url模块
- node.js学习(十八、URL模块)
- Node.js中的OS模块
- Node.js中的Path模块
- Node.js中的Console模块
- Node.js中的DNS模块
- Node.js中的Net模块
- Node.js中的Assert模块
- Node.js中的HTTP模块
- caffe安装指南
- Reading for graduate students
- 快速排序
- jsp 四大作用域
- 软件测试工作的几个认识误区
- Node.js中的URL模块
- UITableView:表视图
- createjs-打豆豆小游戏制作(2)
- sql over开窗函数
- CentOS 安装 JAVA
- shell脚本:统计订单信息
- Android实战技巧:深入解析AsyncTask
- 2049 不容易系列之(4)——考新郎
- 每日一“结”(8)