📜  节点 |网址.密码API

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

节点 |网址.密码API

url.password是类 URL的内置应用程序编程接口,带有 in url模块,用于获取和设置 URL 的密码部分。

句法:

const url.password

返回值:获取和设置 URL 的密码部分。
下面的程序说明了url.password方法的使用:
示例 1:

javascript
// node program to demonstrate the
// url.password API as Setter
  
//importing the module 'url'
const http = require('url');
  
// creating and initializing myURL
const myURL = new URL('https://pqr:abc@example.com');
  
// Display password
// value of myURL before change
console.log("Before Change");
console.log(myURL.password);
  
// assigning password portion
// using password API
console.log();
 
// Changing the myUrl.password for the above URL
myURL.password = '123';
  
// Display the changed password
// value of myURL after change
console.log("After Change");
console.log(myURL.href);


javascript
// node program to demonstrate the
// url.password API as Getter
 
//importing the module 'url'
const http = require('url');
 
// creating and initializing myURL
const myURL = new URL('https://example.org/foo#ram');
myURL.password = '1234'
 
// getting the password portion
// using password
const password = myURL.password;
 
// Display hostname value
console.log("password is : "+password);
console.log(myURL.href);


输出



示例 2:

javascript

// node program to demonstrate the
// url.password API as Getter
 
//importing the module 'url'
const http = require('url');
 
// creating and initializing myURL
const myURL = new URL('https://example.org/foo#ram');
myURL.password = '1234'
 
// getting the password portion
// using password
const password = myURL.password;
 
// Display hostname value
console.log("password is : "+password);
console.log(myURL.href);

输出:

注意:上述程序将使用 Node.js 中的 myapp.js 命令编译和运行。
参考:
https://nodejs.org/api/url.html#url_url_password