【问题标题】:Handling redirected URL within Flex app?在 Flex 应用程序中处理重定向的 URL?
【发布时间】:2010-04-01 15:17:30
【问题描述】:

我们有一个 Flex 客户端和一个使用 Spring/Blazeds 项目的服务器。

用户登录并通过身份验证后,spring 安全层会发送一个重定向到一个新的 URL,这是我们的主应用程序所在的位置。

但是,在 flex 客户端中,我目前正在使用 HTTPService 进行初始请求,并且我将重定向页面完整地发回给我。

我怎样才能获取 URL,以便我可以使用 navigatetourl 来获取应用程序需要去的地方?

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 你能发一些代码吗?

标签: apache-flex http spring url blazeds


【解决方案1】:

一种解决方案是在返回页面的注释块中包含一个标记,例如:

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

然后检查它是否存在于 HTTPService 结果处理程序中。然后可以在您对 navigateToURL 的调用中使用该令牌的值。

另一种解决方案是检查 HTTP 响应标头并使用 ActionScript 提取“Location”标头的值。考虑使用 AS3 HTTP 客户端库。

从示例页面http://code.google.com/p/as3httpclientlib/wiki/Examples 确定响应中的“位置”标头:

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);

注意:AS3 HTTP 客户端依赖于 AS3 Core 和 AS3 Crypto 库。

【讨论】:

  • 对不起 - 这是一个迟到的回复,但这个回复非常有帮助!
【解决方案2】:

您也可以简单地使用 URLLoader 类,无需外部代码。它调度的事件之一是HTTPStatusEvent.HTTP_RESPONSE_STATUS。只需插入它并检索重定向的 url:

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

我现在(成功地)使用此代码,所以如果由于某种原因它不起作用,请告诉我。

【讨论】:

    猜你喜欢
    • 2010-09-20
    • 1970-01-01
    • 2021-08-21
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 2010-10-18
    • 2015-07-30
    • 2010-12-31
    相关资源
    最近更新 更多