1

我正在尝试使用 actionscript 抓取网页,但不断收到此错误(尝试抓取 github.com 的示例):

[SWF] /get-webpage.swf - 解压后 2,708 字节错误:来自 http://localhost:4567/get-webpage.swf的请求者对http://github.com的资源请求 因缺乏政策而被拒绝文件权限。

* 违反安全沙箱 *与http://github.com的 连接停止 - 不允许来自http://localhost:4567/get-webpage.swf

有什么方法可以在 Actionscript 中进行这项工作吗?文件如何crossdomain.xml发挥作用?据我了解,网站将 a 作为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);

是否有可能绕过该安全错误?

4

1 回答 1

7

简短的回答,不。

中等答案,不。我看到 github 这里有一个跨域 xml 策略。 https://github.com/crossdomain.xml

这是 flash 在尝试从另一个域获取内容时自动加载的文件。

这个xml文件是说,只允许github上的flash吸取数据。所以 github 已经明确表示他们不希望你使用 flash 来加载他们的任何内容。

<?xml version="1.0" encoding="UTF-8"?>
<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFile.xsd">
  <allow-access-from domain="github.com" />
    <allow-access-from domain="gist.github.com" />
    <site-control permitted-cross-domain-policies="master-only"/>
</cross-domain-policy>

我认为这种 flash 行为的原因是人们 + 公司会信任 flash。我认为这种机制可以防止大规模的 DOS 攻击(想想在新闻网站上加载的 Flash 横幅,比如 github,它可能会导致大量负载)。

您可以通过电子邮件发送 github 并将您的域添加到他们在跨域文件中的列表中,但这可能需要一些时间和大量的政治。

长答案,是的。您可以使用 PHP 或其他东西创建一个 HTTP 代理来拉入网页。PHP 或代码必须在您加载 SWF 文件时在同一个域上运行。例如 youdomain.com/folder/proxy.php 。您基本上必须要求此代理在 PHP 中获取您的网页并将结果返回到 Flash。整个过程有点痛苦,尤其是当您使用必须发送参数或 HTTP 标头的 Web 服务时。您可以在线安装开源 PHP 代理文件。

祝你好运!回到与梅根福克斯一起看变形金刚2。哦耶。

于 2010-07-11T07:44:51.870 回答