Android Http Post Login

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Android Http Post Login

Postby guydor » Mon Jun 27, 2011 6:00 am

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().toString();
String password = this.passwordField.getText().toString();

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
guydor
Freshman
Freshman
 
Posts: 2
Joined: Sun Jun 26, 2011 7:36 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 8 guests