我试图使POST请求对node.jsurl,但总是得到ERROR 401(未经授权)。
const response = await fetch('url', {
method: 'POST',
mode: 'no-cors',
headers: {
"Content-Type": "text/html; charset=utf-8",
"Authorization": 'Basic ' + Buffer.from('username' + ":" + "password", 'base64').toString('base64')
},
body: ''
});
我尝试使用btoa,但是node.js不支持…
headers.set('Authorization', 'Basic ' + btoa(username + ":" + password));
try this:
let loginData = "username" + ":" + "password";
let encodedData = new Buffer(loginData);
let base64data = encodedData.toString('base64');