1

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


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?

Community
  • 1
  • 1
Flemingjp
  • 139
  • 3
  • 14
  • Which is the question? What's your problem? – Enrichman Jan 11 '16 at 22:49
  • Im wanting to find the URL of the page once the post request has returned successful. Ive attempted similar solutions, that I've linked to, which finds a list of redirected URLs or the last know URL. - I've updated the question now to try reflect this question better – Flemingjp Jan 11 '16 at 22:53
  • Have you tried setting `client.setEnableRedirects(true)`? – Enrichman Jan 11 '16 at 23:01
  • @Enrichman Yes, apologies that is part of the code I've omitted – Flemingjp Jan 11 '16 at 23:04

0 Answers0