WebGL CORS error when trying to get text from a URL. Even when CORS is set?
I'm trying to load high scores for my game from this URL: https://dirtylime.com/games/highscores/display.php?game=space_runner
Since uploading the WebGL build to a seperate domain it's failing to get the URL. I'm getting this Cross-Origin Resource Sharing error in the browser console:
Access to XMLHttpRequest at 'https://dirtylime.com/games/highscores/display.php?game=space_runner' from origin 'https://uploads.ungrounded.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
But my webpage does have a Access-Control-Allow-Origin header set to * so I can't figure out what could be stopping it.
I can confirm that the header is set using an online testing tool. http://tools.seobook.com/server-header-checker/?url=https%3A%2F%2Fdirtylime.com%2Fgames%2Fhighscores%2Fdisplay.php%3Fgame%3Dspace_runner&useragent=8≺otocol=11
Here's the C# code I'm using to try load the URL:
UnityWebRequest hs_get = UnityWebRequest.Get(highscoreURL);
yield return hs_get.SendWebRequest();
if (hs_get.isHttpError) {
scoresText.text = "There was an error getting the highscores:\nPlease try again.";
} else {
scoresText.text = hs_get.downloadHandler.text;
}
Your answer
Follow this Question
Related Questions
Error in BUILD with UnityWebRequest but not in Editor 0 Answers
Upload progress of file on unity WebGl 0 Answers
Establish a constant connection to a web server 0 Answers
UnityWebRequest, C# request.accept equivalent? 0 Answers
How to make a script wait for a UnityWebRequest to finish for WebGL without a coroutine? 1 Answer