问题描述:

How can I login to a website (http://www.myhopaccount.co.nz/CWP/ - - - - you'll be redirected to the actual website) through an android application? I have looked at almost all the questions here already. Everytime I send the data, when I retrieve the information, I always get info from the login page.

Can anyone show me a code to use to login to that website through an app, or link me to somewhere useful? I've tried different methods (jsoup, httpclient) but still nothing.

This is my most recent attempt: (username/password are obtained from text fields)

Thread thread = new Thread() {

public void run() {

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("myhopaccount.co.nz/CWP/");

try {

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

nameValuePairs.add(newBasicNameValuePair("ctl00$contentPlaceHolder$UsernameTextBox", username));

nameValuePairs.add(new BasicNameValuePair("ctl00$contentPlaceHolder$PasswordTextBox", password));

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);

Log.v("StatusCode", "Response from server: " + response.getStatusLine().getStatusCode());

} catch (ClientProtocolException e) {

System.out.println("CPE: " + e.getMessage());

} catch (IOException e) {

System.out.println("IOE: " + e.getMessage());

}

}

};

thread.start();

And before that, I tried this solution: Performing login to https website via Android app

However, that only returned the source code of the login page.

相关阅读:
Top