I’m trying to make a login to my website via an Android app.
For some reason something always goes wrong.
Here’s my site login structure:
Login.php– the login form (username
& password)Auth.php– login authentication page
(gets the username & password from
page – login.php (POST method))
I already have to interface with Username & Password (EditText both)
What is the method to make a login via android app?
here’s my current login method
private void login() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
/* login.php returns true if username and password is equal to saranga */
HttpPost httppost = new HttpPost("my auth.php file url");
try {
// Add user name and password
String username = this.usernameField.getText();
String password = this.passwordField.getText();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Thanks
A few days ago I had some similar problems.
You can have a look at the following code.