I'm struggling to get an XMLHttpRequest POST to work. If you look at the url, RequestHeader and body content (see the myJSON), I can use those parameters in PostMan and the POST works just fine. If however I try to do it in my HTML from the function below I get the following error:
Access to XMLHttpRequest at 'http://ccinformatics.medstar.net/ccinformaticsapi/api/providers' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status. [file:///D:/Data/VSCode/CCInformatics/CCInformatics/iisstart.html#] Failed to load resource: net::ERR_FAILED [http://ccinformatics.medstar.net/ccinformaticsapi/api/providers]
I'm not sure why this mentions CORS as this fails even when the HTML is run off the domain that has both the IIS and SQL servers.
The mentioned url is a private one so you won't be able to hit it. Some of the error code shows file:/// as I was in my development environment when I created this question.
function PostNewUser() {
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var x = JSON.parse(xhttp.responseText);
};
}
var obj = { index: "ff406552-fc83-4bdb-92fe-001af107ac32", providerNumber: "18", name: "Test, Person", logon: "ppp3", password: "0", userRoles: "CCB3User", active: false, passwordHash: "b660901f90afbdc4216fbf91f185c5c7", taxIdgroup: "Attending", npinumber: "NULL", rowversion: "AAAAAAAAB+I=" };
var myJSON = JSON.stringify(obj);
var url = "http://ccinformatics.medstar.net/ccinformaticsapi/api/providers";
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send(myJSON);
}