📜  Node.js urlObject.auth API

📅  最后修改于: 2022-05-13 01:56:24.194000             🧑  作者: Mango

Node.js urlObject.auth API

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

示例 #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);

输出 :