我使用Apache HttpClient 4.3.2 lib向页面site.com
发送GET请求,服务器可以将我重定向到site.com/home
或site.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个多小时才找到解决方案,但还没找到。