I am not able to make a post-call using xmlhttprequest in javascript. First, I am getting a 401 response code from server-side. Below is code I am using below code.
function makeRestCall(){
console.log("Rest call made")
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert(this.responseText);
}
};
xhttp.open("POST", "myurk", false, 'username', 'password');
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send()
alert(xhttp.status);
alert(xhttp.responseText)
I am also getting
"Request has been blocked by CORS policy"
I am able to do a rest call from postman and using basic auth and getting response also
I have referred various links for making a rest call using javascript.
But still, I am not able to resolve the error. Can anyone tell what is wrong am I doing.