Enter the user name and password on the logon page. After Successful Logon, the system jumps to the homepage. If the logon fails, an error message is displayed. When passing parameters, use the List of BasicNameValuePair as httpPost. setEntity. You cannot use HttpParams.
UserName = (EditText) this. findViewById (R. id. editTextUserName); password = (EditText) this. findViewById (R. id. editTextPassword); errorMsg = (TextView) this. findViewById (R. id. textViewLoginMsg); Button loginBtn = (Button) this. findViewById (R. id. btnLogin); loginBtn. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View arg0) {String result;/* Send part */try {HttpClient httpClient = new Def AultHttpClient (); String address = strUrl; HttpPost httpPost = new HttpPost (address); List <BasicNameValuePair> params = new parameter List <BasicNameValuePair> (); params. add (new BasicNameValuePair ("username", userName. getText (). toString (); params. add (new BasicNameValuePair ("password", password. getText (). toString (); httpPost. setEntity (new UrlEncodedFormEntity (params, "UTF-8"); // enter the parameter in the POST Entity HttpResp Onse httpResponse = httpClient.exe cute (httpPost);/* receive */if (httpResponse. getStatusLine (). getStatusCode () = 200) {result = EntityUtils. toString (httpResponse. getEntity ();/* json text parsing */JSONTokener jsonParser = new JSONTokener (result); JSONObject jsonResult = (JSONObject) jsonParser. nextValue (); String status = jsonResult. getString ("loginStatus"); String outMessage = jsonResult. getString ("outMessage "); If (status. equals ("true") {Intent I = new Intent (LoginActivity. this, MainActivity. class); I. putExtra ("username", outMessage); startActivityForResult (I, FIRST_REQUEST_CODE);} else {errorMsg. setVisibility (View. VISIBLE); errorMsg. setText (outMessage) ;}} else {errorMsg. setVisibility (View. VISIBLE); errorMsg. setText ("network connection problem. CODE: "+ httpResponse. getStatusLine (). getStatusCode ();} catch (JSONException e) {e. printStackTrace ();} catch (UnsupportedEncodingException e) {e. printStackTrace ();} catch (ClientProtocolException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();}}});