WebGL CORS policy error on POST and GET

Hello everyone

185377-hata.png

I am currently experiencing CORS policy error on my WebGL build, I Tried everything on my application side and server side

I Tried appConfiguration.AddCors() or adding CORS header to the project but neither of them didnt worked.

Is there anybody could help about this topic?
I am getting this error on local and in server app

Well this is most likely related to using localhost as domain and it could also be an issue that you currently serve your own web content over http while the apis you try to reach are https.

I don’t know the two APIs you’re trying to use, but they need to provide a CORS header in order to allow foreign domains to access their service. If they don’t, you can’t use them from your site. Though as I said, some browsers may not allow localhost content at all. Also mixing secured and non secured content can also cause all sorts of security barriers in the browser to kick in.

So if you’re sure that the APIs actually contains an Access-Control-Allow-Origin header that either allows every domain (so it contains a wildcard *) or allows your own domain explicitly, it should work when you use an actual domain name. Note for local testing you could simply “invent” a domain name by adding it to your hosts file on your machine that simple maps to 127.0.0.1.

The second potential issue is the mixing of http with https. You should host your own stuff also on https. For this you can install a self-signed certificate on your local server and accept that certificate in the browser manually. The other alternative is to use lets-encrypt to generate a valid SSL certificate for free. However this requires that you have an actual domain name. I have a free sub-domain name that maps to my public router IP, so my server is actually reachable from the internet. I have created a lets-encrypt certificate for my domain that is usually accepted in all browsers.

If you don’t need any serverside logic on your local server, so you only use it to host your WebGL build, you can also host your WebGL content on an actual webspace. If you have a github account you can use “github pages” to host the website there. Here’s my repository where I host most of my WebGL example builds. Github pages provide https and a “proper” domain name for free. See if that fixes your issue.