Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

How do Cookies work in Flex?

New Here ,
May 13, 2009 May 13, 2009

Let's start with the goal. I need cookies to work as they do in any 'normal' browser.

I have a Flex application that will be calling a webservice(REST service at url http://www.abc.xyz/setcookie) and the service returns a response and a cookie.  The service actually only records any cookies that it gets and returns another cookie along with a message of what it got in the cookie and what it set in the cookie. If I call this service in a browser (Mozilla) then the first time through there is no cookie but one is set and returned.  The 2nd time calling with Mozilla I get the message that there is 1 cookie in the request and one is set and returned. All is well.

I code a flex application to simply call this service and try to decode the response. But am having problems.

1. Can't find the cookie in the ResultEvent. Look in the headers that are available (using Debug) but they don't seem to be there. Are they in the container? (Browser)?

2. When I make an HTTP Request using an HTTPService

    <mx:HTTPService id="restServiceSetCookie"
        url="http://localhost:8080/SimpleRESTapp/setcookie"
        result="resultHandler(event)"
        fault="faultHandler(event)"
        />      

... and then call it multiple times, the server always records that 0 cookies were sent with this request. I would have expected that it would be 0 the first time and then it would be 1 the next time as the cookie that was set by the server the first time was returned. The result handler simple prints out the text message from the server saying how many cookies it got with the request and the cookie data.

Am I missing something fundamental in how Flex or the container (Browser) works with regard to cookies? Do you really have to reimplement cookie handling with every Flex application? I don't want to use Local Shared Objects as I would have to change the services that are being used presently. Any help or direction to look would be appreciated.

Thanks

Cam

13.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 14, 2009 May 14, 2009

Cam,

there is no native support for cookies in AS3, but have a look at

http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1724523

or search for CookieUtil in the Adobe Flex libraries. This is a small class that you can add to projects and then get/set at will. I have found it very easy to use.

Richard

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 14, 2009 May 14, 2009

Thanks Richard. I was aware of that library but was really wishing that Flex would handle cookies in some built-in/reasonable fashion since they are so ubiquitous.  Just for giggles, what actually happens to the cookies? I.e. it looks to me like the HTTPService class must make it's call to the remote service without including cookies that would normally be passed by the browser and the same in response. ie. the browser or someone must strip the cookies from the response before passing it to the Flash VM. A complete HTTP response would include the cookies would it not?

I ran the response from the server in debug mode and hunted through the ResultEvent to the my call to this remote service that sets a cookie in the response and there was no where in the ResultEvent  that had the cookie or anything resembling a cookie. So something is actively stripping them. It may just be the browser/container but it seems very strange to me that the response would not be complete when it is returned to the Flex VM.

Does anyone have any further information on this?

Thanks

Cam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 02, 2009 Jun 02, 2009

flash.net.URLRequest

AIR-only manageCookies : Boolean

Specifies whether the HTTP protocol stack should manage cookies for this request.
Works for AIR only.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2011 Nov 10, 2011
LATEST

Hi Cam,

Im working on a air app with the smae requirement as yours, do you got any luck with your project. If so please help me reading the cookies.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines