【发布时间】:2010-07-11 07:27:34
【问题描述】:
我正在尝试使用 actionscript 抓取网页,但不断收到此错误(尝试抓取 github.com 的示例):
[SWF] /get-webpage.swf - 解压后 2,708 字节 错误:请求者从 http://github.com 请求资源 http://localhost:4567/get-webpage.swf 由于缺少策略文件权限而被拒绝。
* 违反安全沙盒 * 与http://github.com 的连接已停止 - 不允许来自http://localhost:4567/get-webpage.swf
有什么方法可以在 Actionscript 中实现这一点? crossdomain.xml 文件是如何发挥作用的?据我了解,网站将crossdomain.xml 放在其根目录下,指定 swf 可以访问其内容。那是对的吗?我需要做什么才能完成上述工作?我正在使用的代码基本上是这样的:
var request:URLRequest = new URLRequest("http://github.com")
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, complete);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, error);
loader.load(request);
function complete(event:Event):void {
trace(event.target.data);
}
function error(event:SecurityErrorEvent):void {
trace(event.text);
}
在 HTML 文件中添加:
var flashvars = {};
var params = {allowscriptaccess: "always"};
var attributes = {id: "my_flash", name: "my_flash"};
swfobject.embedSWF("/get-webpage.swf", "flash_content", "50%", "50%", "10.0.0", "playerProductInstall.swf", flashvars, params, attributes, swfHasLoadedSir);
是否有可能绕过该安全错误?
【问题讨论】:
标签: apache-flex flash security crossdomain.xml