我正在Flex (AS3)中创建一个应用程序,我需要从外部url获取信息。但是当使用URLLoader时,错误发生:
我的代码:"Error # 2044: Unhandled securityError:. "text =错误# 2048:安全沙箱违规"
sUrlListas = "https://www.us8.api.mailchimp.com/2.0/lists/members.json?apikey=XXXXX&id=XXX;
urlLoader2 = new URLLoader ();
urlLoader2.load (new URLRequest (sUrlListas));
我的交叉域是:
<cross-domain-policy>
<site-control permitted-cross-domain-policies = "all" />
<allow-access-from domain = "*" secure = "false" to-ports = "*" />
</ cross-domain-policy>
跨域它们是:
<cross-domain-policy>
<allow-access-from domain = "*" />
</ cross-domain-policy>
在本地主机上执行此应用程序。我读了很多关于跨域be的问题,但似乎并不是这个问题。
有人能帮忙吗?
默认情况下,flash crossdomain中的"secure"属性被设置为true,这意味着您不能从HTTP访问HTTPS上的内容。因此,swf应该从HTTPS连接到它们的API。
在我的情况下,问题是类似的,设置跨域策略也没有帮助我。所以我尝试请求api服务不是直接从SWF,而是通过我的web上的php代理。就像:
private static var agentURL:String = "https://myweb.com/agent.php";
private function sendRequest():void
{
var service:HTTPService = new HTTPService();
service.resultFormat = "e4x";
service.useProxy = false;
service.method = "POST";
service.url = agentURL;
var params:Object = new Object();
params.myurl = "https://www.us8.api.mailchimp.com/2.0/lists/members.json?apikey=XXXXX&id=XXX";
service.send(params);
}
/*some listeners for Result and Fault response */
下一个代码是文件agent。php
<?php
set_time_limit(100);
$url = $_POST['myurl'];
try
{
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
if (curl_errno($curl)) {
print "CError: " . curl_error($curl);
} else {
print($result);
curl_close($curl);
}
}
catch(Exception $e)
{
print '<message>' . $e->getMessage() . '</message>';
}
finally
{
curl_close($curl);
}
?>