I am trying to make POST and GET requests to a local .NET Core Web API. I learned about the CORS problem for the first time today and I am able to get GET requests to work by simply installing the Google Chrome extension called "Allow-Control-Allow-Origin: *".
However, my POST request fails each time due to the CORS policy. It is so annoying and I can't find an easy or reliable work-around. I am not too considered about making CORS work in every browser. Even if I could get it to work in Google Chrome alone with be a life saver.
I've looked around and there isn't a streamlined solution that has worked for me yet.
My call to the Web API looks like this from within my React App.
axios.post('https://localhost:44395/api/record/create', { Status: "Initiated", Owner: "Peter Porcupine", DateTimeCreated: new Date().getTime(), LastTimeCreated: new Date().getTime(), Comment: { TimeStamp: new Date().getTime(), Text: "Comment sent to API." }})
.then(response => {
console.log("Response below from post request");
console.log(response);
});
The call returns a 404, and I also get the following error: Access to XMLHttpRequest at 'https://localhost:44395/api/record/create' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I tried to make the POST request using Postman with a similar body and it works and updates my database. I'm certain it isn't an issue related to what body I send the API.