apache-flex “错误#2048:将URLLoader与外部URL一起使用时出现安全沙箱违规”

8wtpewkr  于 2022-11-01  发布在  Apache
关注(0)|答案(2)|浏览(215)

我正在Flex(AS3)中创建一个应用程序,需要从外部url获取信息。但在使用URLLoader时出现错误:
“错误编号2044:未处理的安全性错误:。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>

我读过很多关于跨域问题的文章,但似乎并不完全是这个问题。
有人能帮忙吗?

dgsult0t

dgsult0t1#

默认情况下,flash crossdomain中的“secure”属性设置为true,这意味着您不能从HTTP访问HTTPS上的内容。因此,您的swf应该从HTTPS连接到他们的API。

5ssjco0h

5ssjco0h2#

在我的例子中,问题是类似的,设置跨域策略也没有帮助我。所以我尝试请求API服务,而不是直接从SWF,而是通过我的网站上的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);
}
?>

相关问题