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


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

語法:

復制代碼 代碼如下:
url.parse(urlStr, [parseQueryString], [slashesDenoteHost])

接收參數:

urlStr url字符串

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

slashesDenoteHost

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

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

例子:

復制代碼 代碼如下: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'
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM