title: Android http Post Login
body: <p>I'm trying to make a login to my website via an Android app.
  For some reason something always goes wrong.</p>
  
  <p>Here's my site login structure:</p>
  
  <ul>
  <li><code>Login.php</code> - the login form (username
  &amp; password)</li>
  <li><code>Auth.php</code> - login authentication page
  (gets the username &amp; password from
  page - login.php (POST method))</li>
  </ul>
  
  <p>I already have to interface with Username &amp; Password (EditText both)</p>
  
  <p>What is the method to make a login via android app?</p>
  
  <p>here's my current login method</p>
  
  <pre><code>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&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(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();
      }
  }
  </code></pre>
  
  <p>Thanks</p>