I am trying to set up an Android app where I can access URL's behind arbitrary proxies or HTTP authentications. That is, the app won't know immediately if a URL needs authentication and will repond to an authentication request by asking the user for credentials, the same way it does for the Android Browser.
I recently worked out how to request user authentication for a WebView, responding to authentication requests from the browser, bringing up a dialog, and advancing the user to the destination page. I am looking to do the same with HttpClient
.
The basic process, as I see it, is to:
- Perform the request via
HttpClient.execute
.- If not 401 or 407 with proper headers, trigger a "done" callback.
- Otherwise...
- Pop up a dialog asking for the username and password.
- Set the http credentials in the HTTP client via
HttpClient.getCredentialsProvider().setCredentials
. - Return to step 1 until the the user clicks cancel or the server gives up. In that case, trigger a "failed" callback with the last response received.
Am I on the right track or has someone already implemented something similar? I would hate to be reinventing the wheel on this.