let base64 = require('base-64'); let url = 'http://eu.httpbin.org/basic-auth/user/passwd'; let username = 'user'; let password = 'passwd'; let headers = new Headers(); //headers.append('Content-Type', 'text/json'); headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password)); fetch(url, {method:'GET', headers: headers, //credentials: 'user:passwd' }) .then(response => response.json()) .then(json => console.log(json)); //.done(); headers.set('Authorization', 'Basic ' + Buffer.from(username + ":" + password).toString('base64')); npm install base-64 --save import { encode } from "base-64"; const response = await fetch(URL, { method: 'post', headers: new Headers({ 'Authorization': 'Basic ' + encode(username + ":" + password), 'Content-Type': 'application/json' }), body: JSON.stringify({ "PassengerMobile": "xxxxxxxxxxxx", "Password": "xxxxxxx" }) }); const posts = await response.json(); // space in "C ontent-Type" const headers = { "C ontent-Type": "text/xml", "Breaking-Bad": "<3", }; fetch("https://example.com/", { headers });