I am trying to implement fetch data using POST method with Basic authentication in JS . But I am receiving the 401 authorization error. I am using below code to implement that. Please let correct below code and me know where I am making mistack.
fetch('https://example.com', {
method: 'POST',
headers: { 'Content-Type': 'application/json'
{Authorization: 'Username': 'testuset',
'Password': 'Testpassword'
}},
body: JSON.stringify({
"FirstName": "test",
"Email": "testtt"
})
})
.then(response => response.text())
.then(contents => console.log(contents))
.catch(() => console.log("Can’t access " + url + " response. Blocked by browser?"))