ASP.Net Core Web API unable to connect due to CORS
Hello,
I want to call my POST-request through Swagger. Yet when I send the request it gives me the following message and shuts down the application;
Undocumented
Failed to fetch.
Possible Reasons:
CORS
Network Failure
URL scheme must be "http" or "https" for CORS request.
I have tried to add CORS into my program.cs but to no avail. How can I solve this, so that I can communicate with my API?
4 Replies
appsettings.json: nothing really useful
docker-compose.override:
docker-compose.yml
Without the CORS stuff, you can remove the following lines of the program.cs;
I see you have setup your HTTP port as 8080 and your HTTPS port as 8081, however in your CORS settings you have reversed them
Hey Anchy, thank you for your reply. I would assume you mean this line of code:
I swapped the 2 but this still gave me the same 'error'

But do i actually need CORS? Because as far as I know, CORS is used when you want to perform HTTP-requests to another domain. In my case everything is local(host).
There is something else wrong. I do not get what it can be...
it was the fockin browser. I used Brave for this, but brave blocked it.
Using Edge works
ARGH