July 10th, 2008 at 6:22 am
Cookies and Actionscript
Submit to del.icio.us
I have been searching and searching today to find out a way to see the cookies that the server sends to you while downloading a page using URLLoader. I needed to read the PHPSESSID cookie that php send me so I could use it again in another URLLoader object so I could download some information that was protected behind a login. With one URLLoader object I sent the necessary form information to the login script and then I would transfer the PHPSESSID cookie to new URLLoader objects to download the information I wanted that was stored on different pages while still being authenticated with the correct session ID.
Sadly tho, after searching long I could not find anything that would tell me how to read the cookies from the URLLoader object or how to transfer them to the new objects. –I found a lot about the Flash Shared Object, but that was not what I was looking for, sadly–
I’m still not sure why, but for some reason I ran the code without copying the session ID to the new object to see what would happen and waddayaknow, I was getting the information I wanted. So somehow cookies are stored automatically from one URLLoader object to another, what struck me as strange, because I thought I would be starting with a clean sheet when I created a new object, not that cookies –and who knows what else– would be stored between them. So next time I will have to find out how to open multiple sessions at the same time, but I’ll do that when I’ll need to.
If anyone does know how to see what cookies were sent and what their value is, please let me know as I’m sure I could use it sometime.
P.S: For anyone wondering what I was making. My university has a special page with all my grades and ECTS credits and I wanted an easy way of checking them and maybe alerting me when the page was updated. So I decided to create it with AIR because some of my classmates –That might find it handy too– have macs while I use a pc, so it would be OS Independent.
filed under 
Latest comment displayed first
September 5th, 2009 // 7:30 am
Yes the URLLoader stores cookies and hence stores cookies needed to maintain a logged in session.
You can turn that functionality off if you want the cookie data in the response headers.
var myLoader = new air.URLLoader();
var myRequest = new air.URLRequest(url);
myRequest.manageCookies = false;
You will need to do this is you want to get a cookie value manually from the headers.
In a air.HTTPStatusEvent.HTTP_RESPONSE_STATUS event loop through the event.responseHeaders and look for event.responseHeaders[i].name == ‘Set-Cookie’ to get the headers.
Hope this helps someone.
June 15th, 2009 // 4:47 pm
Hi, interest post. I’ll write you later about few questions!
May 25th, 2009 // 7:48 am
Pretty cool stuff. What are you studying at Uni? I fear my life will be gone once I get into Actionscript. Yeah, we have the same name, they actually added a d because the priest said Ezrad is androgynous. I have a cousin named Ezrad too. sorry for freaking out I dont meet too many people with that name, in fact, none.
good day
Leave a Reply