node.js中的url.parse方法使用說明

一個URL字符串轉換成對象並返回。ui

語法:url

複製代碼 代碼以下:
url.parse(urlStr, [parseQueryString], [slashesDenoteHost])對象

接收參數:字符串

urlStr url字符串get

parseQueryString 爲true時將使用查詢模塊分析查詢字符串,默認爲falsehash

slashesDenoteHostconsole

默認爲false,//foo/bar 形式的字符串將被解釋成 { pathname: ‘//foo/bar' }class

若是設置成true,//foo/bar 形式的字符串將被解釋成 { host: ‘foo', pathname: ‘/bar' }require

例子:語法

複製代碼 代碼以下:var url = require('url');
var a = url.parse('http://example.com:8080/one?a=index&t=article&m=default');
console.log(a);

//輸出結果:
{
protocol : 'http' ,
auth : null ,
host : 'example.com:8080' ,
port : '8080' ,
hostname : 'example.com' ,
hash : null ,
search : '?a=index&t=article&m=default',
query : 'a=index&t=article&m=default',
pathname : '/one',
path : '/one?a=index&t=article&m=default',
href : 'http://example.com:8080/one?a=index&t=article&m=default' }

相關文章
相關標籤/搜索