I had my client hosted on localhost:8080/ and the server on localhost:44302/
I am attempting to connect to my backend, but I keep encountering CORS issues. Here is my Angular http request:
$http.post(url, data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS'
}
}).success(function (response) {
// additional code here
}).error(function (err, status) {
// additional code here
});
On the server side, written in C#, I have configured the response as follows:
Response.ContentType = "application/json";
Response.AddHeader("Access-Control-Allow-Origin", "*");
Response.AddHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
Despite setting these configurations, I continue to receive the following error:
XMLHttpRequest cannot load https://localhost:44302/some_uri. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 400.
What could be the missing piece in this setup?