当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Node.js urlObject.auth用法及代码示例

借助 urlObject.auth() 方法,我们可以在主机名中找到身份验证参数。该方法返回参数字符串。

用法:

urlObject.auth()  

返回:返回认证参数的字符串。

示例 1:在此示例中,借助 urlObject.auth() 方法,我们能够从主机名中提取用户名和密码。

javascript


// importing the module 'url' 
const url = require('url');
const adr =
'https://username=jitender:password=geeks@www.geeksforgeeks.com';
// Parse the address:
const q = url.parse(adr, true);
/* The parse method returns an object containing
 URL properties */
console.log(q.auth);

输出:


示例 2:在此示例中,借助 urlObject.auth() 方法,我们能够从主机名中提取用户名和密码。

javascript


// importing the module 'url' 
const url = require('url');
const adr =
'https://username=author:password=truegeek@www.gfg.com';
// Parse the address:
const q = url.parse(adr, true);
/* The parse method returns an object containing
 URL properties */
console.log(q.search);

输出:


相关用法


注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 Node.js urlObject.auth API。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。