Reputation:
I want to send get request to .NET API which is working in Nginx server. But i can't get any response,only cors errors.
axios.get(`http://localhost:${port}/${api}`)
.then((res) => {
console.log(res);
response = res;
});
When i send request like that. It gives me this error:
Cross-Origin Request Blocked: The Same Origin Policy disallows
reading the remote resource at
I have changed my code a bit. And this is like that:
axios.get(`http://localhost:${port}/${api}`, {
headers: {
"Access-Control-Allow-Origin": true,
"Access-Control-Allow-Headers": "Content-Type",
},
withCredentials: true,
})
.then((res) => {
console.log(res);
response = res;
});
And it gives me CORS did not succeed error. How can i prevent that?
Upvotes: -1
Views: 318
Reputation: 2363
There is no solution for you from the front-end. This is for security purpose. What you need to do is allow cors in your .NET backend API server.
You can learn from here https://www.c-sharpcorner.com/article/cors-in-dotnet-core/
Upvotes: 1