我有一个 fla(使用 ActionScript 3.0),我正在 Flash 中编译。我正在使用 URLRequest 和 URLLoader 来访问 http 网络服务。
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 保护的页面上?
最佳答案
如果您安装了 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" />
进一步阅读:
关于ssl - SWF(使用 URLLoader)可以访问 HTTPS 网络服务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1387608/