AS3 + HTTP GET 不起作用 [英] AS3 + HTTP GET doesn't work

查看:22
本文介绍了AS3 + HTTP GET 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Flash 中有一个项目,我使用带有一些数据的网络服务器.我阅读了该信息(json):

I have a project in Flash and I use a webserver with some data. I read that information (json) with:

var url:String = "URL REQUEST";
var request:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.load(request);

我在 TextField 中使用该信息.这工作正常并正确显示我的数据.但是,当我发布我的作品或打开文件时,.swf 不显示数据.

and I use that information in a TextField. This works fine and show my data properly. But, when I publish my work or open the file .swf doesn't show the data.

在 Adob​​e Flash 内部工作正常.外面不行.

Inside the Adobe Flash works fine. Outside doesn't work.

我有一个在 nodeJS 中运行服务的树莓派.路由器的门是开着的.

I have a raspberry pi with a service in nodeJS running. The door is open in the router.

我的 nodeJS

var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
const port = process.env.PORT || 3001;
const SERVER_ROOT = "http://localhost:" + port;
var messages =  {};
messages["a1"] = blablabla;
--
messages["n"] = blablabla;
function buildMessage(newID, text, user){
const now = new Date();
return {

    };
};
app.route("/message") 
.get(function(req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");

    res.json(messages);
});
app.param('messageID', function(req, res, next, messageID){
req.messageID = messageID;
return next();
})
app.listen(port, function() {
console.log("Listening on " + port);
});

推荐答案

这是一个典型的安全错误,当 swf 尝试加载其他域中的内容而不是它自己的域并且没有执行此操作的授权时会触发该错误.因此,为了避免这种类型的安全错误,您必须在要加载数据的服务器的根目录下创建一个 crossdomain.xml 文件.要更深入地了解事物,请查看此架构(从 Adobe 跨域策略文件) :

This is a classic security error which is fired when an swf try to load content in another domain other than its own and didn't has authorization to do that. So to avoid this type of security error, you have to create a crossdomain.xml file at the root of the server from where you want to load data. To more understand things, take a look on this schema ( taken, and edited, from Adobe Cross Domain Policy File) :

所以在这种情况下,为了允许 a.com 中的 swf 文件从 b.com 加载数据,我们必须添加一个 crossdomain.xml 文件在 b.com 的根目录中,因此我们可以使用 b.com/crossdomain.com 访问它.有关此文件的内容和更多详细信息,您可以查看上面的跨域规范链接.它可以是这样的:

So in this case, to allow an swf file in a.com to load data from b.com, we have to add a crossdomain.xml file in the root of b.com, so we can access to it using b.com/crossdomain.com. For the content of this file and more details about it, you can see the link above of the crossdomain specification. It can be like this :

<?xml version="1.0"?>
<cross-domain-policy>
    <!-- if used alone, allow only all a.com requests but not its sub-domains -->
    <allow-access-from domain="a.com"/>
    <!-- if used alone, allow all a.com sub-domains and a.com requests -->
    <allow-access-from domain="*.a.com"/>
    <!-- if used alone, allow only b.a.com sub-domain requests -->
    <allow-access-from domain="b.a.com"/>
</cross-domain-policy>

我希望所有这些都可以帮助您解决问题.

I hope all this can help you to resolve your problem.

这篇关于AS3 + HTTP GET 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆