2011-01-20 26 views
0

我尝试从httprequest获取https地址的结果时遇到了史诗般的困难。 我正在从地址加载策略文件,但我仍然收到2048安全错误。使用flex从https地址加载策略文件

我在我的preinitilize处理程序中加载我的策略文件。

private function preint(e:FlexEvent):void 
      { 
       Security.loadPolicyFile("https://api.soundcloud.com/crossdomain.xml"); 
      } 

我的服务器给我回一个特殊的记号,我需要,然后我尽量让我到需要使用URLRequest和URLLoader资源的请求。

private function getprivatetracks():void 
     { 
       var url:String=new String("https://api.soundcloud.com/me/tracks?oauth_token=" + testapplicationparameters["oauth_token"]) 
      var req:URLRequest=new URLRequest() 
      req.contentType="application/x-www-form-urlencoded" 
      req.method=URLRequestMethod.GET; 
      req.url=url; 

      var loader:URLLoader=new URLLoader() 
      loader.dataFormat=URLLoaderDataFormat.TEXT; 
      loader.dataFormat="text"; 
      loader.load(req); 
      configureListeners(loader); 


     } 

如果我描绘出我打电话的网址,并将其粘贴到浏览器,我可以看到的结果很好。这纯粹是一件闪光的事情。 当我从flex IDE以调试模式运行swf时,请求正常工作。只有当swf位于服务器上时才会出现此问题。

我已经度过了一天的最美好时光,试图解决这个问题。

有人可能会提示我可能会做错什么吗?

我在猜测我缺乏关于flash如何处理https的一些基本知识。

编辑1

Error: Request for resource at https://api.soundcloud.com/me/tracks?oauth_token=0000000NBfKiNXEYG00FWTUGAy5Uw68r by requestor from http://myserver/content/flash/soundcloud/sclive.swf is denied due to lack of policy file permissions. 

*** Security Sandbox Violation *** 
Connection to https://api.soundcloud.com/me/tracks?oauth_token=0000000NBfKiNXEYG00FWTUGAy5Uw68r halted - not permitted from http://myserver/content/flash/soundcloud/sclive.swf 
Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://myserver/content/flash/soundcloud/sclive.swf cannot load data from https://api.soundcloud.com/me/tracks?oauth_token=0000000NBfKiNXEYG00FWTUGAy5Uw68r. 
    at sclive/getprivatetracks()[C:\flex_projects\sclive\src\sclive.mxml:74] 
    at sclive/authorize_result_handler()[C:\flex_projects\sclive\src\sclive.mxml:62] 
    at flash.events::EventDispatcher/dispatchEventFunction() 
    at flash.events::EventDispatcher/dispatchEvent() 
    at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:763] 
    at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:263] 
    at mx.rpc::Responder/result()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:46] 
    at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74] 
    at DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.5.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:409] 
    at flash.events::EventDispatcher/dispatchEventFunction() 
    at flash.events::EventDispatcher/dispatchEvent() 
    at flash.net::URLLoader/onComplete() 

EDIT 2

我试图捕捉安全错误事件,并检查URL以确保世界上没有重定向回事,但处理程序不会被调用!即使我已经为它写了一个处理程序,我总是会得到非受限的异常错误。

+0

你能张贴整个错误信息? – 2011-01-20 10:40:43

回答

0

出于安全原因,不建议允许HTTP内容访问HTTPS内容。 因此,如果soundcloud想要允许HTTP内容访问其数据,他们应该在crossdomain.xml中指定它(在allow-access-from标签中使用属性secure =“false”)。

不过,我只注意到也有在http一个跨域: http://api.soundcloud.com/crossdomain.xml

所以我建议你使用,而不是HTTPS这个网址,并shloud工作

+0

那么,我还没有详细检查soundcloud API,所以我不能真正说。但它看起来像是有一个API的AS3包装: https://github.com/dorianroy/Soundcloud-AS3-API/wiki 顺便说一句,你不需要调用Security.loadPolicyFile(“https:/ /api.soundcloud.com/crossdomain.xml“); – 2011-01-20 13:01:18