【问题标题】:"Error #2048: Security sandbox violation" when using URLLoader with external Url使用带有外部 URL 的 URLLoader 时出现“错误 #2048:违反安全沙箱”
【发布时间】:2014-10-15 10:48:12
【问题描述】:

我正在 Flex (AS3) 中创建一个应用程序,我需要从外部 url 获取信息。但是在使用 URLLoader 时会出现错误:

“错误#2044:未处理的安全错误:。文本=错误#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> 

在 localhost 上运行此应用程序。我已经阅读了很多关于跨域问题的信息,但似乎并不完全是这个问题。

有人可以帮忙吗?

【问题讨论】:

    标签: actionscript-3 security apache-flex cross-domain flex4.5


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      默认情况下,Flash 跨域中的“安全”属性设置为 true,这意味着您无法从 HTTP 访问 HTTPS 上的内容。因此,您的 swf 应该从 HTTPS 连接到他们的 API。

      【讨论】:

        猜你喜欢
        • 2011-09-05
        • 1970-01-01
        • 2011-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-01
        • 1970-01-01
        相关资源
        最近更新 更多