Peroblema with httpResponseMsg.equalsIgnoreCase

1

Hol, I'm creating an android app but I have an error that has me unprepared because I never would have happened this before.

    public void UpdateState(final String iddispositivo, final String iduser, final String uubicacion) {
        class UpDni extends AsyncTask<String, Void, String> {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();

                progressDialog = ProgressDialog.show(Home.this, "Accediendo", null, true, true);
            }

            @Override
            protected void onPostExecute(String httpResponseMsg) {
              super.onPostExecute(httpResponseMsg);
                progressDialog.dismiss();
                if (httpResponseMsg.equalsIgnoreCase("correcto")) {
                    Toast.makeText(getBaseContext(), "Proceso exitoso", Toast.LENGTH_LONG).show();
                    finish();
                    Intent intent = new Intent(Home.this, Home.class);
                    startActivity(intent);
                } else {
                    Toast.makeText(getBaseContext(), "Proceso Incorrecto ", Toast.LENGTH_LONG).show();
                    Toast.makeText(Home.this, httpResponseMsg, Toast.LENGTH_LONG).show();
                }
            }

            protected String doInBackground(String... params) {

                hashMap.put("iddispositivo", params[0]);
                hashMap.put("iduser", params[1]);
                hashMap.put("ubicacion", params[2]);
                finalResult = httpParse.postRequest(hashMap, updatee);
                return finalResult;
            }
        }
        UpDni UPD = new UpDni();
        UPD.execute(iddispositivo, iduser, uubicacion);
    }

It turns out that always in the if it throws me incorrect process and then shows the "correct" message that if it is adequately replenishing the server, at first I thought it was a server problem and decided to try it in the following way in the .php

if($_SERVER['REQUEST_METHOD']=='POST'){
////////////////si no se cumple if (($calendarioid != '') && ($usubloq == '0'))
$incidenciaid = $_POST['iddispositivo
']
$usuarioid = $_POST['iduser'];
$ubicacion = $_POST['ubicacion'];
 echo "correcto";
}   

In theory, it should always show me a successful process, but it shows me an incorrect process and prints "correct", that is, if it is receiving properly.

    
asked by Yoel Mendoza 14.01.2018 в 23:10
source

1 answer

1

I could assure you that the answer does not actually return "correct" or returns it with spaces or other characters, to verify this add the String of the answer in the case of not finding the word "correct", I suggest also use the trim() method to eliminate spaces at the ends:

  if (httpResponseMsg.trim().equalsIgnoreCase("correcto")) {

Example:

    @Override
    protected void onPostExecute(String httpResponseMsg) {
      super.onPostExecute(httpResponseMsg);
        progressDialog.dismiss();
        if (httpResponseMsg.trim().equalsIgnoreCase("correcto")) {
            Toast.makeText(getBaseContext(), "Proceso exitoso", Toast.LENGTH_LONG).show();
            finish();
            Intent intent = new Intent(Home.this, Home.class);
            startActivity(intent);
        } else {
            Toast.makeText(getBaseContext(), "Proceso Incorrecto!, mensaje: " + httpResponseMsg, Toast.LENGTH_LONG).show();
        }
    }
    
answered by 15.01.2018 / 20:57
source