Created
January 3, 2010 15:09
-
-
Save nicoulaj/267996 to your computer and use it in GitHub Desktop.
A utilitary function to handle authenticated sessions when using URLRequests in ActionScript. Just reads the JSessionId from the user cookie and appends it to the URI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Build the URL to call with the session ID | |
*/ | |
public static function buildAuthenticatedURL(url : String):String | |
{ | |
if (jsessionid == null) { | |
// Get the cookie | |
ExternalInterface.call('eval','window.getCookie = function () {return document.cookie};'); | |
var cookie : String = ExternalInterface.call('getCookie'); | |
// Extract the JSESSIONID value | |
var regexp : RegExp = new RegExp("JSESSIONID=([\\d\\w]*)","ig"); | |
cookie = cookie.match(regexp)[0]; | |
var jsessionid : String = cookie.split("=")[1]; | |
} | |
return url + ";jsessionid=" + jsessionid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment