I tried to use fetch with this syntax:
fetch(\"https://user:password@url\", {
...
}).then((response) => {
...
}).done();
The same url
I found that this format https://user:password@url
works well in CURL and node but not with fetch.
I had to use base-64
npm module and pass through a Headers object.
// https://www.npmjs.com/package/base-64
const base64 = require('base-64');
...
var headers = new Headers();
headers.append("Authorization", "Basic " + base64.encode("user:password"));
fetch("https://url", {
headers: headers
})
.then((response) => { ... })
.done();
`
You could have used btoa()
instead of using the base_64
module. btoa()
is a function on the Window
.