节点 | urlObject.auth API
借助urlObject.auth()方法,我们可以在主机名中找到身份验证参数。此方法返回参数字符串。
Syntax : urlObject.auth()
Return : Returns the string of authentication parameter.
示例#1:在这个示例中,借助 urlObject.auth() 方法,我们能够从主机名中提取用户名和密码。
javascript
// importing the module 'url'
const url = require('url');
var adr =
'https://username=jitender:password=geeks@www.geeksforgeeks.com';
// Parse the address:
var q = url.parse(adr, true);
/* The parse method returns an object containing
URL properties */
console.log(q.auth);
javascript
// importing the module 'url'
const url = require('url');
var adr =
'https://username=author:password=truegeek@www.gfg.com';
// Parse the address:
var q = url.parse(adr, true);
/* The parse method returns an object containing
URL properties */
console.log(q.search);
输出 :
示例#2:
javascript
// importing the module 'url'
const url = require('url');
var adr =
'https://username=author:password=truegeek@www.gfg.com';
// Parse the address:
var q = url.parse(adr, true);
/* The parse method returns an object containing
URL properties */
console.log(q.search);
输出 :