I have a WebView in which I am loading a certain Url with a login page (www.yahoo.com). When the user enters his username and password and hits the login button, I want to track the response of the web page so that I can use this for issuing a token.

Right now when I hit the login button the WebView loads the next default page after sign in like it would do in a normal browser. I want to redirect the web page to some other Url.

I have done this:-

myWebView.loadUrl(url);
myWebView.setWebViewClient(new MyWebViewClient()
{
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
if(progressBar.isShowing())
{
progressBar.dismiss();
}

}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
HttpClient httpClient = new DefaultHttpClient();
URL myUrl;
URLConnection connection;
try
{
myUrl = new URL(url);
connection = myUrl.openConnection();
connection.setConnectTimeout(3000);
connection.connect();

int size = connection.getContentLength();

}
catch (Exception e) {}

String htmlContent = “”;
HttpGet httpGet = new HttpGet(url);
HttpResponse response;

try
{
response = httpClient.execute(httpGet);
if(response.getStatusLine().getStatusCode() == 200)
{
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = entity.getContent();
htmlContent = convertToString(inputStream);

}
}
}
catch (Exception e) {}

view.loadUrl(url);
Toast.makeText(getApplicationContext(), htmlContent, Toast.LENGTH_LONG).show();
return true;

}

});

But this traces the response when the login page loads and not after the user has logged in.
I cannot figure out how this can be done. Any ideas will be helpful

Thanks.

Read more here: Getting response from a sites login page android


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: