Quantcast
Channel: Questions in topic: "httpwebrequest"
Viewing all articles
Browse latest Browse all 190

Unity Web Request: CORS error on WebGL hosted on AWS but works on editor

$
0
0
Hi everyone! As a part of my authentication system in my web gl app, I need to request the Squarespace API to check for orders to confirm that the current user has purchased a subscription. I am currently doing this by doing a web request to the API endpoint by adding a header with the API key. This then should return a JSON which I can format into the data I need. This works perfectly on windows & editor builds, however when deploying the WebGL app and hosting it on AWS (embedded in my Squarespace website), I get this error: Access to fetch at 'https://api.squarespace.com/1.0/commerce/orders?cursor=' from origin 'https://3dtinyhousebuilderfreev1.s3.ap-southeast-2.amazonaws.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. I am aware that the response needs to have the "Access-Control-Allow-Origin", however I am unsure how I can change that, as I do not own the Squarespace api server, hence not being able to change any settings. Here is the code handling the request: //----Communicate with server and get squarespace data-----// string apiRequestURL = "https://api.squarespace.com/1.0/commerce/orders?cursor="; var request = new UnityWebRequest(apiRequestURL, "0"); request.downloadHandler = new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Authorization", "Bearer APIKEY");// My code actually contains the API key, I just can't display it here ;) //request.SetRequestHeader("Access-Control-Allow-Origin", "*"); - I tried this, this did not make a difference. yield return request.SendWebRequest();//Returns the result of the request Dictionary downloadedData; downloadedData = new(JsonConvert.DeserializeObject>(request.downloadHandler.text));//Turns data into the Dictionary downloadedData I am not sure where to start with this, so any help is very appreciated!!! If you want to replicate the error, load my development build here: https://www.tinyeasy.co.nz/bugtest-3d-tiny-house-designer The error appears as soon as you try login/signup.

Viewing all articles
Browse latest Browse all 190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>