[英]Loading Policies files from https address with flex
嘗試從httprequest到https地址獲取結果時,我遇到了巨大的困難。 我正在從地址加載策略文件,但仍然收到2048安全錯誤。
我像這樣在預初始化處理程序中加載策略文件。
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);
}
如果我找出要調用的URL,然后將其粘貼到瀏覽器中,則可以看到正確的結果。 這純粹是一瞬間。 當我從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()
編輯2
我嘗試捕獲安全錯誤事件並檢查url,以確保沒有進行任何重定向,但永遠不會調用該處理程序! 即使為它編寫了處理程序,我也總是收到無法處理的異常錯誤。
出於安全原因,建議不要允許HTTP內容訪問HTTPS內容。 因此,如果soundcloud希望允許HTTP內容訪問其數據,則應在crossdomain.xml中指定它(使用allow-access-from標記中的屬性secure =“ false”)。
但是,我剛剛注意到http上還有一個跨域:http: //api.soundcloud.com/crossdomain.xml
因此,我建議您使用此URL而不是HTTPS,它可以正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.