如何在重定向后从响应对象获取URI?

时间:2014-02-07 16:06:09

标签: scala apache-httpclient-4.x

我使用Apache HttpClient 4.3.2 lib向页面site.com发送GET请求,服务器可以将我重定向到site.com/homesite.com/login或不重定向。如何从HttpResponse对象获取URI?

def checkLogin(rawRequest: HttpRequestBase) = {
  val client = HttpAsyncClients.custom().setRedirectStrategy(new LaxRedirectStrategy()).useSystemProperties().build()
  client.execute(rawRequest, new FutureCallback[HttpResponse] {
    def completed(result: HttpResponse) = {
      if (result.getURI() == "site.com/login") // this is what I want! (or something like)
        parent ! ErrorMsg
      else
        parant ! OkMsg
    }
  })
}

我花了2个多小时才找到解决方案,但还没找到。

0 个答案:

没有答案