AS3 + HTTP GET不起作用

编程入门 行业动态 更新时间:2024-10-23 15:31:02
本文介绍了AS3 + HTTP GET不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Flash中的项目,我使用了一些数据的网络服务器。我读到的信息(JSON)有:

变种网址:字符串=URL请求; VAR要求:的URLRequest =新的URLRequest(URL); VAR装载机:的URLLoader =新的URLLoader(); loader.load(要求);

和我使用的文本字段的信息。这工作正常,并正确显示我的数据。但是,当我发表我的工作或打开.swf文件不显示数据的文件。

里面的Adobe Flash正常工作。 外面是行不通的。

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

我nodeJS

VAR EX preSS =需要('EX preSS'); VAR bodyParser =需要('身体解析器'); VAR应用= EX preSS(); app.use(bodyParser.json()); app.use(bodyParser.urlen codeD({扩展:真})); 常量口= process.env.PORT || 3001; 常量SERVER_ROOT =HTTP://本地主机:+端口; 变种消息= {}; 消息[A1] = blablabla; - 消息[N] = blablabla; 功能buildMessage(NEWID,文本,用户){ 常量现在=新的日期(); 返回 {     }; }; app.route(/消息) 获得(功能(REQ,RES){     res.header(访问控制 - 允许 - 起源,*);     res.header(访问控制 - 允许 - 头,X-要求,随着);     res.json(消息); }); app.param('MESSAGEID',功能(REQ,资源,接下来,邮件ID){ req.messageID = MESSAGEID; 返回下一个(); }) app.listen(端口,函数(){ 的console.log(听的+端口); });

解决方案

这是被解雇当SWF尝试加载另一个域之外的其它内容,并没有拥有授权做一个经典的安全错误。因此,为了避免这种类型的安全错误的,你必须创建一个的crossdomain.xml 文件在服务器从要加载数据的根源。为了更明白的事情,采取这种模式一看(取,和编辑,从的Adobe跨域策略文件):

因此,在这种情况下,允许在 a 的SWF文件从 b 加载数据,我们有在 b 的根添加的crossdomain.xml 文件,所以我们可以利用访问它 b/crossdomain 。对于这个文件,有关它的更多细节的内容,你可以看到上面的跨域规范的链接。它可以是这样的:

< XML版本=1.0&GT?; <交域政策>     <! - 如果单独使用,仅允许所有a请求,但不是它的子域 - >     <允许存取来自域=a/>     <! - 如果单独使用,允许所有a子域和a请求 - >     <* a允许访问,从域= />     <! - 如果单独使用,仅允许bacom子域的请求 - >     <允许存取来自域=b.a/> < /跨域策略>

我希望这一切可以帮助你解决你的问题。

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);

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.

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

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

My 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); });

解决方案

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) :

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

发布评论

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

>www.elefans.com

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