SWF(使用URLLoader)可以访问HTTPS Web服务吗?

时间:2009-09-07 05:01:26

标签: ssl https flash urlrequest

我有一个fla(使用ActionScript 3.0)我在Flash中编译。我正在使用URLRequest和URLLoader来访问http web服务。

var loader:URLLoader = new URLLoader();     
var request:URLRequest = new URLRequest("http:test.webservice.com");    
try {
   loader.load(request);
} catch (error:Error) {
   trace("Unable to load requested document.");
}

这很好 - 但是如果我尝试访问https地址,我会

httpStatusHandler: [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=0]
ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: https://test.webservice.com"]

如何从https网络服务中检索数据? SWF是否必须托管在SSL安全页面上?

2 个答案:

答案 0 :(得分:6)

如果您安装了Flash调试播放器,您可能会在日志中看到以下内容:

** Security Sandbox Violation ***
Connection to https://www.example.com/service/ halted - not permitted from http://www.example.com/your.swf

Error: Request for resource at https://www.example.com/service/ by requestor from http://www.example.com/your.swf is denied due to lack of policy file permissions.

默认情况下,http中托管的swf无法访问https - 它被视为不同的域。

您需要设置相应的crossdomain.xml策略文件,并小心验证Content-Type是text / *还是其他列入白名单的值。此外,您还需要一个带有“secure = false”的元策略文件,该文件允许从http访问https。

  <allow-access-from domain="www.example.com" secure="false" />

进一步阅读:

Policy file changes in Flash Player 9 and Flash Player 10

答案 1 :(得分:2)

检查actionscript文档中的跨域策略 http://kb2.adobe.com/cps/142/tn_14213.html

  

一种安全服务器,允许访问通过非安全托管的电影   协议

     

不建议允许HTTP内容访问HTTPS内容。   这种做法可能会损害HTTPS提供的安全性。

     

但是,可能存在允许传统Flash内容的情况   访问HTTPS站点的数据。使用Flash Player 7,不再是这样   默认允许。允许Flash影片访问HTTPS数据   通过HTTP提供,使用“allow-access-from”标记中的secure属性   并将其设置为false。

 
 <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">


        <cross-domain-policy>


        <allow-access-from domain="www.company.com" secure="false" />


        </cross-domain-policy> 
  

它保存为crossdomain.xml并放在网站的根目录下   HTTPS服务器。