参数说明
parse(urlstr, bol)
urlstr 字符串 被解析的url字符串,如:http://www.liboke.cn:8080?name=liboke&num=100#abc
bol 布尔 true:使用querystring模块的parse()方法解析"?"后的字串
false:不使用
返回值:对象数组
| 返回值(属性) | 描述 | 说明 |
|---|---|---|
| href | 被解析的URL字符串 | http://www.liboke.cn:8080/index.html?name=liboke&num=100#abc |
| protocol | 使用的协议 | "http" |
| slasjes | 布尔,协议后是否使用"//"分割 | true |
| host | 地址+端口号 | liboke.cn:8080 |
| auth | 认证信息部分 | |
| hostname | 地址、IP、主机名 | liboke.cn |
| port | 端口号 | 8080 |
| pathname | "?"号前的路径 | /index.html |
| search | "?"号后的查询字符串,包含"?" | ?name=liboke&num=100 |
| query | "?"号后的查询字符串,不包含"?" | name=liboke&num=100 |
| path | 路径包含查询字符串 | /index.html?name=liboke&num=100 |
| hash | 散列字符串,包含"#" | #abc |
示例
var url = require("url");
var obj = url.parse("http://www.liboke.cn:8080/index.html?name=liboke&num=100#abc");
注:如设置bol=true,返回值中 query属性,将使用querystring模块的parse()方法解析