我正在制作一个游戏,使用Haxe和Flambe库,目标是flash&html5 5。我需要用http-请求访问REST-api。为此,我使用了Haxe的Http-class。下面是我目前的测试代码:
public function getRocketStatus():Void
{
var urlLoader:Http = new Http("https://seginus-scores.herokuapp.com/api/MailboxMayhem/Highscores/");//"localhost:8000/api/rocket");
// add parameters
//urlLoader.addParameter("myVar", "myValue");
//urlLoader.addParameter("userName", "Mark");
// callbacks
urlLoader.onError = function (msg) {requestCompleteSignal.emit(msg);};
//urlLoader.onStatus = function(status) {requestCompleteSignal.emit(Std.string(status));};
urlLoader.onData = function(data)
{
trace('Sending data completed! data=$data');
requestCompleteSignal.emit(data);
}
// sends to data using GET
urlLoader.request();
// sends to data using POST
urlLoader.request(true);
}每次我试着用它,我都会出错:
*** Security Sandbox Violation *** Connection to https://seginus-scores.herokuapp.com/api/MailboxMayhem/Highscores/ halted - not permitted from http://localhost:7000/targets/main-flash.swf如果我从Flambe测试服务器、我的本地apache服务器等使用它,它就不起作用了。我还知道,在我的API中,跨域策略应该是正确的,因为我可以很好地将它与我之前制作的Unity和Java游戏连接起来。但是,我从html5 5目标收到了js-控制台的以下错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource.我已经检查了这个Haxe页面,这个页面在主题:http://old.haxe.org/doc/flash/security上有点模糊。
我以前在AS3中做过url请求,并且不得不处理安全沙箱问题。然而,在这些情况下,将跨域添加到另一端似乎解决了这个问题,这与这里的情况不同。
发布于 2014-06-08 14:04:56
好吧,我发现问题了。我现在觉得很蠢。当我使用localhost时,我忘记添加"http://“到url”(例如。http://localhost:8000/api),并忘记从上面的调用中删除https,而我只有http可用。
https://stackoverflow.com/questions/24106060
复制相似问题