WebGL access issues - download assets at runtime from server

Hello, I have already read Unity Documentation and this thread.

Yet I still have several concern about a Unity WebGL build of mine.

In fact, I am trying to make requests from our website to our server API. For instance, my WebGL content is located on server.fr and we are making a GET request to server.fr. I’m using Unity’s tool UnityWebRequest to perform this. Nevertheless, when I have fully built myWebGL content and exported it on server.fr, those requests are forbidden. I still can’t figure out why this is not working and I’m sure my requests are correctly implemented on my server API.
Do you know how to solve this problem ?

Thanks.

if you are hosting on the same server (including subdomain) which you want to access, there should not be restrictions. Do you see any errors in the browser console?

Yes indeed : “Failed to load resource: the server responded with a status of 403 (Forbidden)”

Hello Angal.
Make sure that not only the domain but also protocol matches. For example, http and https would be considered different origins.

I have checked multiple times that I am indeed accessing the right domain with the right protocol. I still can’t understand why I have an error here…

If you are familiar with XMLHttpRequest, then you can try to debug this issue outside of the Unity code. Just perform the request to the very same resource directly from the JavaScript on your index page, and check if you still get 403. Also, check the network profiler in the browser, it will give you a lot of important information, check if your request is preflighted and, if possible, attach the screenshot.

I tried to perform the request from the JavaScript, and I indeed still get 403.

Here are screenshots of the code I used and the errors I get thereafter, the website adress is hidden for privacy issues concerning our project.

I tried first this (with single quotation marks and with double quotation marks, I only attached the first case) :
2688078--190099--Error Code 1.png

Then this :
2688078--190100--Error Code 2.png

All I got was :
2688078--190101--First Error website.png

Then :
2688078--190102--Second error website.PNG

Any suggestion ? Thanks for all the aforementioned advices.

If you can not access the resource from pure JavaScript using XMLHttpRequest (assuming that the resource starts with http:// which part you would not have any reason to censor), then I would assume that it is either a cross-origin request, or the resource is not available from the browser address line (which you can try).
I would also recommend you to use the browser network profiler, which is accessible from the Network tab near the Console tab in most browsers, it gives additional information, i.e. about preflighted requests etc. The network profiler also gives you information about the full resource path being accessed, in case if you are using an incorrect relative path.

Thank you so much for your help Alex. It turns out that our problem was indeed a server restriction, since we are not working directly on the server, there has been some misunderstanding, and now our request is working effectively !