Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 闪存策略文件不工作(同一域,不同端口)_Flash_Cross Domain Policy - Fatal编程技术网

Flash 闪存策略文件不工作(同一域,不同端口)

Flash 闪存策略文件不工作(同一域,不同端口),flash,cross-domain-policy,Flash,Cross Domain Policy,我不知所措。我不明白为什么Flash没有正确加载我的策略文件。我正在用Flash调试器测试这个 I've also tried from http://127.0.0.1:80/game (it sends a request to http://127.0.0.1:3014/socket.io/1/). 错误: > webSocketLog: policy file: xmlsocket://127.0.0.1:843 Error #2044: > Unhandled secur

我不知所措。我不明白为什么Flash没有正确加载我的策略文件。我正在用Flash调试器测试这个

I've also tried from http://127.0.0.1:80/game (it sends a request to http://127.0.0.1:3014/socket.io/1/).
错误:

> webSocketLog: policy file: xmlsocket://127.0.0.1:843 Error #2044:
> Unhandled securityError:. text=Error #2048: Security sandbox
> violation: file:///ude/game/bin-release/Game.swf cannot load data from
> http://127.0.0.1:3014/socket.io/1/?time=1359025067289.    at
> com.pnwrain.flashsocket::FlashSocket()
但这是可行的:

> echo -ne '<policy-file-request/>\0' | nc -v 127.0.0.1 843  

Connection to 127.0.0.1 843 port [tcp/*] succeeded!
<?xml version='1.0' ?>
<!DOCTYPE cross-domain-policy SYSTEM 'http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd'>
<cross-domain-policy>
    <allow-access-from domain='*' to-ports='*' />
</cross-domain-policy>
即使这样也不行(来自一篇非常流行的博客文章的解决方案):


导入flash.system.Security;
安全性。allowDomain(“http://127.0.0.1");

以下是调试器策略文件日志:

> OK: Root-level SWF loaded:
> file:///ude/game/bin-release/Game.swf
> OK: Searching for <allow-access-from> in policy files to authorize
> data loading from resource at
> http://127.0.0.1:3014/socket.io/1/?time=1359026453454 by requestor
> from
> file:///ude/game/bin-release/Game.swf
> Error: [strict] Ignoring policy file at
> http://127.0.0.1:3014/crossdomain.xml due to missing Content-Type. 
> See http://www.adobe.com/go/strict_policy_files to fix this problem.
> Error: Request for resource at
> http://127.0.0.1:3014/socket.io/1/?time=1359026453454 by requestor
> from
> file:///ude/game/bin-release/Game.swf
> is denied due to lack of policy file permissions. Warning: HTTP
> response headers not available on this platform.  Strict policy file
> rules cannot be enforced. OK: Policy file accepted:
> http://127.0.0.1:843/crossdomain.xml
URLRequest
之前。因此,我将
URLRequest
移动到setTimeout中,现在日志显示:

> OK: Root-level SWF loaded:
> file:///ude/game/bin-release/Game.swf
> Warning: HTTP response headers not available on this platform.  Strict
> policy file rules cannot be enforced. OK: Policy file accepted:
> http://127.0.0.1:843/crossdomain.xml OK: Searching for
> <allow-access-from> in policy files to authorize data loading from
> resource at http://127.0.0.1:3014/socket.io/1/?time=1359028255268 by
> requestor from
> file:///ude/game/bin-release/Game.swf
> Error: [strict] Ignoring policy file at
> http://127.0.0.1:3014/crossdomain.xml due to missing Content-Type. 
> See http://www.adobe.com/go/strict_policy_files to fix this problem.

非常感谢您的任何想法。谢谢大家!

我对策略文件不在行,但这看起来很可疑:

错误:[strict]忽略位于的策略文件
http://127.0.0.1:3014/crossdomain.xml
由于缺少内容类型。 请参阅以解决此问题

似乎忽略了策略文件,因为它没有或没有无效的内容类型头

从版本9,0115,0开始,Flash Player将忽略任何未发送内容类型值的HTTP策略文件,该值在一定程度上保证该文件是文本文件。Flash Player要求策略文件的内容类型必须为以下类型之一:

  • text/*(任何文本类型)
  • application/xml
    application/xhtml+xml
这是:

如果您发现需要解决内容类型问题,请务必参阅上的部分,因为选择元策略的常见方法是为所有策略文件指定特殊内容类型
text/x-cross-domain-policy
,它可以同时解决两个问题:建立元策略和提供文本内容类型

还要检查服务器HTTP响应头不可用的原因:

警告:HTTP响应头在此平台上不可用。严格的 无法强制执行策略文件规则


希望这有帮助。

成功连接和策略验证的关键是:

1) 在socket.io脚本所在的文件夹中有一个crossdomain.xml文件

2) 在运行socket.io服务器的同一主机:端口中通过http提供此crossdomain.xml

3) 要实现这一点,除了socket.io之外,还需要安装express framework。使用express和socket.io,您可以在同一端口上同时通过http和连接套接字为crossdomain.xml提供服务

4) 使用此方法,flash可以在最初查找此策略文件的位置(同一主机:端口)找到crossdomain.xml,从而避免了手动从flash加载策略文件的需要(您可以禁用loadPolicyFile)

大概是这样的:

var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);

app.get('/crossdomain.xml', function (req, res) {
  console.log("request ... " + __dirname);
  res.sendfile(__dirname + '/crossdomain.xml');
});

server.listen(port, "ip");
console.log("socket.io server started");

嗨,两张脸!是的,但是在我明确指定了策略文件的查找位置之后,HTTP请求产生了这个错误。已加载。我理解为什么它试图为HTTP URL加载一个,它可能有一个子策略文件。由于内容类型错误,它会忽略第一个策略文件?我不确定,但可能您需要套接字主策略文件,该文件将从端口843提供服务。似乎现在您必须为套接字连接提供特殊的策略文件。请看这里
Security.loadPolicyFile('http://127.0.0.1:843/crossdomain.xml');
> OK: Root-level SWF loaded:
> file:///ude/game/bin-release/Game.swf
> Warning: HTTP response headers not available on this platform.  Strict
> policy file rules cannot be enforced. OK: Policy file accepted:
> http://127.0.0.1:843/crossdomain.xml OK: Searching for
> <allow-access-from> in policy files to authorize data loading from
> resource at http://127.0.0.1:3014/socket.io/1/?time=1359028255268 by
> requestor from
> file:///ude/game/bin-release/Game.swf
> Error: [strict] Ignoring policy file at
> http://127.0.0.1:3014/crossdomain.xml due to missing Content-Type. 
> See http://www.adobe.com/go/strict_policy_files to fix this problem.
Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: file:///ude/game/bin-release/Game.swf cannot load data from http://127.0.0.1:3014/socket.io/1/?time=1359028255268.
    at MethodInfo-3642()
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at SetIntervalTimer/onTimer()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);

app.get('/crossdomain.xml', function (req, res) {
  console.log("request ... " + __dirname);
  res.sendfile(__dirname + '/crossdomain.xml');
});

server.listen(port, "ip");
console.log("socket.io server started");