Error when inserting data accentuated

Asked

Viewed 1,008 times

0

I am sending the data by URL to my webservice if I put the path by example web browser in Chrome: meuwebservice/inserirusu/João_da_Silva/fotógrafo and call a method to display shows so:

Nome: João da Silva
profi: Fotógrafo

Now when I call the method to follow it shows me so:

Nome: Jo?o da Silva
profi: Fot?grafo

I put to display the path I’m going through Android and is the same that I put by Chrome.

 private void inserir(final String edicao) {  edicao = "João_da_Silva/fotógrafo
    showProgressDialog();

    StringRequest strReq = new StringRequest(Request.Method.GET,
            Const.URL_EDITAR_TRABALHADOR+edicao, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, response.toString());
            if(response.equal("Alterado"){
               hideProgressDialog();
               finish();
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            hideProgressDialog();

        }
    });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

}

How can I fix this?

I was making a mistake to display on logcat and showed me that this so android

meuwebservice/inserirusu/Jo?o_da_Silva/fot?grafo

more I displayed before sending and the path is correct in System

1 answer

2


You need to encode the url the right way, when you type it in the browser’s address bar it already does it automatically and so it works.

You can use the URLEncoder.encode for this, remembering that it should encode only the parts that may have accent or other special characters

String edicao = URLEncoder.encode("João da Silva", "UTF-8") + "/" + URLEncoder.encode("Fotógrafo", "UTF-8");

It should also solve the problem of spaces, which in a URL should be replaced by a + sign and not by underline.

  • It worked when I used now is giving step example error á and so sends : %C3%A1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.