Skip to content

Instantly share code, notes, and snippets.

@nicoulaj
Created January 3, 2010 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoulaj/267996 to your computer and use it in GitHub Desktop.
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.
/**
* 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