SigninActivity.java (Cont.)

protected String doInBackground( String... arg0 ) {
It invoked on the background thread immediately after onPreExecute finishes executing. This step is used to perform background computation that can take a long time. The specified parameters are the parameters passed to execute(Params...) by the caller of this task. The result of the computation must be returned by this step and will be passed back to the last step.

URLEncoder.encode( username, "UTF-8" );
Translates a string into application/x-www-form-urlencoded format using the specific encoding scheme UTF-8.

URLConnection conn = url.openConnection( );
Returns a URLConnection instance that represents a connection to the remote object referred to by the URL.

conn.setDoOutput( true);
Sets the value of the doOutput field for this URLConnection to the specified value. A URL connection can be used for input and/or output. Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.

conn.getOutputStream( ) );
It returns an output stream that writes to this connection.

wr.flush( );
Flushes the stream and forces any buffered output to be written out.

protected void onPostExecute( String result ) {
Runs on the UI thread after doInBackground(Params...). The specified result is the value returned by doInBackground(Params...).
Server/app/src/main/java/com/wenchen/server/SigninActivity.java
package com.wenchen.server;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.TextView;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class SigninActivity extends AsyncTask<String, Void, String> {
  private TextView statusField, roleField;
  private Context context;
  private int byGetOrPost = 0;

  // Flag 0 means GET and 1 means POST. (By default it is GET.)
  public SigninActivity( Context context, TextView statusField, TextView roleField, int flag ) {
    this.context     = context;
    this.statusField = statusField;
    this.roleField   = roleField;
    byGetOrPost      = flag;
  }

  protected void onPreExecute( ) { }

  @Override
  protected String doInBackground( String... arg0 ) {
    try {
      String username = (String) arg0[0];
      String password = (String) arg0[1];
      String link     = "http://undcemcs01.und.edu/~wen.chen.hu/cgi-bin/520/14/";

      // Complete the URL.
      if ( byGetOrPost == 0 ) { // Get method
        link += "LoginGet.cgi";
        link += "?username=" + URLEncoder.encode( username, "UTF-8" );
        link += "&password=" + URLEncoder.encode( password, "UTF-8" );
      }
      else { // Post method
        link += "LoginPost.cgi";
      }

      // Connect to the server.
      URL url = new URL( link );
      URLConnection conn = url.openConnection( );
      conn.setDoOutput( true );

      // Send the arguments via standard output for the POST method.
      if ( byGetOrPost == 1 ) { // Post method
        String data  = URLEncoder.encode( "username", "UTF-8" ) + "=";
               data += URLEncoder.encode( username,   "UTF-8" ) + "&";
               data += URLEncoder.encode( "password", "UTF-8" ) + "=";
               data += URLEncoder.encode( password,   "UTF-8" );
        OutputStreamWriter wr = new OutputStreamWriter(
          conn.getOutputStream( ) );
        wr.write( data );
        wr.flush( );
      }

      // Read server response.
      BufferedReader reader = new BufferedReader(
        new InputStreamReader( conn.getInputStream( ) ));
      StringBuilder sb = new StringBuilder( );
      String      line = null;
      while (( line = reader.readLine( ) ) != null ) {
        sb.append( line );
        break;
      }
      return sb.toString( );
    }
    catch( Exception e ) {
      return new String( "Exception: " + e.getMessage( ) );
    }
  }

  @Override
  protected void onPostExecute( String result ) {
    this.statusField.setText( "Login Successful" );
    this.roleField.setText  ( result );
  }
}




      Sure, come into the office, and we can get    
      the documents you need chop chop (quickly).