I am developing an Android app, and I need to logon to a webpage. For that I use HttpPost. This is what I am doing:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://202.163.117.123:8080/hitrack/default.aspx");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("__EVENTTARGET", ""));
nameValuePairs.add(new BasicNameValuePair("__EVENTARGUMENT", ""));
nameValuePairs.add(new BasicNameValuePair("username", "user123"));
nameValuePairs.add(new BasicNameValuePair("Password", "pass456"));
nameValuePairs.add(new BasicNameValuePair("ButtonLogin0", "Login"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
Log.d("response",responseBody);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But this shows me the source of same loginPage. Why does it not redirect to other page? Do I have to add a redirect handler. If yes, then do I to implement it?
I have tried, but that also didn't work.