Im using the LoopJ - Async Http Client For Android to perform some async post requests to login to a website. Im using the AsyncHttpRequestHandlers to keep the process async and seperate from the Android UI thread.
I want to get the page URL after the request - usually the HTTP Response is 200, with ocassional 3xx responses, in between the onSuccess method. Im unsure how I get access to the page URL.
Ive seen various solutions that use synchronous or deprecated methods
- Getting URL after a redirect using HttpClient.Execute(HttpGet) - Synchronous
- Obtaining URL from http response when no location header is sent - Synchronous
- Apache HttpClient: Location of redirected URLs - Deprecated
- HttpClient 4 - How to capture last redirect URL - Deprecated (Redirect Strategy)
Current Code Structure
static AsyncHttpClient client = new AsyncHttpClient();
static {
client.setUserAgent(USER_AGENT);
client.setEnableRedirects(true);
}
public static void login(String user, String password) {
RequestParams params = new RequestParams();
params.put("login", user);
params.put("password", password);
client.post(LOGIN_URL, params, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
//Get Final Url Of Page
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//Handle Failure
}
});
}
Is there a possible solution that I can easily integrate with this structure, whilst retrieving the current page url once the post request has been successful?