需要在 AIR 上設置 cookie 標頭,使用 SWFLoader 檢索遠程 Flex .swf 文件 (Need to set cookie header on AIR use of SWFLoader to retrieve remote Flex .swf file)


問題描述

需要在 AIR 上設置 cookie 標頭,使用 SWFLoader 檢索遠程 Flex .swf 文件 (Need to set cookie header on AIR use of SWFLoader to retrieve remote Flex .swf file)

Am coding an AIR 1.5 app in which I want to do a remote load of a Flex .swf file from a web server.

I'm using Flex 3.2 SDK and attempting to use the sub-application feature via SWFLoader. I've been referencing the Developing and loading sub-applications document on how to do this.

I can indeed successfully load the Flex .swf file from a remote web server and it is loaded into a remote sandbox. The running forms of this .swf file even respect the transparency setting I've set on the AIR native window.

Here is the rub:

For a production situation, our web server uses Spring Security to deflect any unauthorized access to a login web page (this is the case for normal development/QA build deployments as well). If a successful login has been done, then the response of the login sets a cookie. This cookie header should be present on all subsequent HTTP interactions that seek to retrieve content from the site.

I can't figure out how to set a cookie header on my uses of SWFLoader to retrieve Flex .swf files.

How can I use SWFLoader to retrieve files from a web site that is being guarded with Spring Security (which is a widely used means of securing access to Java-based web sites - it used to be called Acegi security before melding with Spring Source).

Running our Flex-based code was a snap when running it in a browser Flash Player sandbox - the Spring Security stuff was managed just swell by the browser. Trying to run our Flex-based app in AIR as a sub-application within the safe confines of a remote sandbox is proving to be a hellish experience, though.

The AIR HTML control, though it works with Spring Security well enough, is a no-go because any .swf or .pdf content loaded will not show up if transparency is set to true on the AIR native window. Our particular UI design absolutely mandates transparency be set to true as we're doing MDI child windows that float on the user desktop.


參考解法

方法 1:

I solved this problem by chaining the use of an AIR HTML control in conjunction to use of SwfLoader to then load the desired remote .swf file.

I wrote a JavaScript function on an HTML web page that my AIR app loads into an HTML instance (when the page complete event fires, it is then safe to call the JavaScript function from AIR Flex code - the Flex code can, of course, handle the HTML complete event).

This JavaScript function uses XmlHttpRequest() to login to the web site that uses Spring Security for authorization. A Set-Cookie header gets processed upon a successful login. When the response for the XmlHttpRequest() is complete then a synthetic click event is dispatched on a dummy DIV object that has been placed on the web page. AIR Flex code is able to register for and process this synthetic click event.

Upon processing the click event, the AIR Flex code then knows it is safe to proceed to instantiate a SwfLoader instance. When the complete event from the SwfLoader object fires, then the object reference of the SwfLoader is placed in the AIR app display list.

The user then sees the remotely loaded swf file begin to execute and show its own UI. It is running in a sub-application remote sandbox context. The sub-application feature is supported in Flex SDK 3.2 via the SwfLoader control.

So the AIR app is managing the cookie header that was established by the HTML control. That cookie header is emitted in the HTTP request of the SwfLoader control when it is used to load the remote .swf file. Spring Security filter sees this and finds the request to be from an authenticated user session.

(by RogerVRogerV)

參考文件

  1. Need to set cookie header on AIR use of SWFLoader to retrieve remote Flex .swf file (CC BY-SA 3.0/4.0)

#air #swfloader #cookies #http-headers #apache-flex






相關問題

如何在 Adobe Air 的 LIKE 運算符模式中使用命名參數 (How to use named parameters inside LIKE operator pattern in Adobe Air)

Android 和 Flash Professional CS 5 Adobe Air Audio:流錯誤 (Android & Flash Professional CS 5 Adobe Air Audio: Stream Error)

可以從 web 視圖中的鏈接觸發我的 Air 應用程序中的操作嗎? (It's possible to trigger an action in my Air app, from a link in a webview?)

動作腳本、NativeProcess、resolvePath 和 swf 不起作用 (Action script, NativeProcess , resolvePath and swf does not work)

如何在創建新線程的同時停止運行線程並恢復同一個線程? (how to stop running thread and resume the same thread beside create new thread?)

我怎樣才能很好地在視圖堆棧之間製作動畫 (How can I nicely animate between viewstacks)

Adobe AIR 從 Flash 是一場大災難? (Adobe AIR from Flash a big disaster?)

“Adobe Flex”和使用 fl.controls 和 fl.events 庫的 AS3 應用程序有什麼區別? (what is the difference between "Adobe Flex" and an AS3 app using fl.controls and fl.events libraries?)

表面上的 Playbook AIR SDK 圖像 (Playbook AIR SDK images on surface)

Adobe AIR 應用程序音頻 (Adobe AIR application audio)

需要在 AIR 上設置 cookie 標頭,使用 SWFLoader 檢索遠程 Flex .swf 文件 (Need to set cookie header on AIR use of SWFLoader to retrieve remote Flex .swf file)

AIR 應用程序的 ActionScript 項目? (ActionScript Project to AIR Application?)







留言討論