[英]Autodesk AR/VR Toolkit Request not working in Unity3d WEBGL?
[英]Unity3d + WebGL = Cross-Origin Request Blocked
我想知道是否有人可以简要解释如何让REST api与基于WebGL平台构建的Unity3D项目一起运行。 我刚刚开始改变我的项目,认为我可以使用REST来解决Parse在我需要制作的WebGL构建中使用线程的问题。 我很快就遇到了CORS问题并且不熟悉它,我不确定如何解决这个问题。
目前,我使用WWW类从Unity发送请求。
“登录”用户的示例是:
WWWForm form = new WWWForm();
var headers = form.headers;
headers["Method"] = "GET";
headers["X-Parse-Application-Id"] = AppID;
headers["X-Parse-REST-API-Key"] = RestID;
headers["X-Parse-Revocable-Session"] = "1";
headers["Content-Type"] = "application/json";
WWW www = new WWW("https://api.parse.com/1/login?username="+name+"&password="+password, null, headers);
这在编辑器中工作正常,但在构建到WEBGL并在Parse上传到我的主机后,会发生以下情况......
我在FireFox中收到以下错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.parse.com/1/login?username=jleslie5159&password=Osulator5159!. This can be fixed by moving the resource to the same domain or enabling CORS.
和Chrome类似的东西......
对于其他人来说,我解决了我的问题:
WWWForm form = new WWWForm();
var headers = form.headers;
headers["X-Parse-Application-Id"] = "AppId";
headers["X-Parse-REST-API-Key"] = "RestKey";
headers["Content-Type"] = "application/json";
WWW www = new WWW("https://api.parse.com/1/login?username="+name+"&password="+password, null, headers);
while(!www.isDone)
yield return 1;
问题源于设置“headers [”Method“] =”GET“”显然只允许发送某些标头或触发CORS违规。 我通过在浏览器控制台中读取响应来解决问题,该响应指定了请求被阻止的原因。 并删除了违规的标题。
我通过在服务器的响应中添加标题Access-Control-Allow-Origin:*来解决。 有关说明,您可以从以下链接中找到答案: https : //developer.tizen.org/dev-guide/2.2.0/org.tizen.web.appprogramming/html/guide/w3c_guide/sec_guide/cors.htm
希望这有帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.