开发者

Handling redirected URL within Flex app?

We have a Flex client and a server that is using the Spring/Blazeds project.

After the user logs in and is authenticated, the spring security layer sends a redirect to a new URL which is where our main ap开发者_开发技巧plication is located.

However, within the flex client, I'm currently using HTTPService for the initial request and I get the redirected page sent back to me in its entirety.

How can I just get the URL so that I can use navigatetourl to get where the app to go where it needs to?

Any help would greatly be appreciated. Thanks!


One solution would be to include a token inside a comment block on the returned page, for instance:

<!-- redirectPage="http://localhost/new-location" -->

then check for it's presence inside the HTTPService result handler. The token's value could then be used in your call to navigateToURL.

Another solution would be to examine the HTTP response headers and extract the value of the "Location" header using ActionScript. Consider using the AS3 HTTP Client lib.

From the examples page http://code.google.com/p/as3httpclientlib/wiki/Examples To determine the 'Location' header from the response:

var client:HttpClient = new HttpClient();

var uri:URI = new URI("http://localhost/j_security_check");

client.listener.onStatus = function(event:HttpStatusEvent):void {
  var response:HttpResponse = event.response;
  // Headers are case insensitive

  var redirectLocation:String = response.header.getValue("Location");
  // call navigateToURL with redirectLocation
  // ... 
};

// include username and password in the request

client.post(uri);

NOTE: AS3 HTTP Client depends on AS3 Core and AS3 Crypto libs.


You can also simply use the URLLoader class, no need for external code. One of the events it dispatches is HTTPStatusEvent.HTTP_RESPONSE_STATUS. Just plug into that and retrieve the redirected url:

urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, onHTTPResponseStatus);
private function onHTTPResponseStatus(event:HTTPStatusEvent):void
{
    var responseURL:String = event.responseURL;
}

I am (successfully) using this code right now, so if it doesn't work for some reason, let me know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜