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?

4
  • Which is the question? What's your problem? Commented Jan 11, 2016 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 Commented Jan 11, 2016 at 22:53
  • Have you tried setting client.setEnableRedirects(true)? Commented Jan 11, 2016 at 23:01
  • @Enrichman Yes, apologies that is part of the code I've omitted Commented Jan 11, 2016 at 23:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.