AS3 + HTTP GET 不起作用

编程入门 行业动态 更新时间:2024-10-23 17:23:28
本文介绍了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 = "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 中的 swf 文件从 b 加载数据,我们必须添加一个 crossdomain.xml 文件在 b 的根目录中,因此我们可以使用 b/crossdomain 访问它.有关此文件的内容和更多详细信息,您可以查看上面的跨域规范链接.它可以是这样的:

So in this case, to allow an swf file in a to load data from b, we have to add a crossdomain.xml file in the root of b, so we can access to it using b/crossdomain. 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 requests but not its sub-domains --> <allow-access-from domain="a"/> <!-- if used alone, allow all a sub-domains and a requests --> <allow-access-from domain="*.a"/> <!-- if used alone, allow only b.a sub-domain requests --> <allow-access-from domain="b.a"/> </cross-domain-policy>

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

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

更多推荐

AS3 + HTTP GET 不起作用

本文发布于:2023-11-23 15:50:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622017.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!