Problem receiving data by GET on android

1
private static PostResponseAsyncTask task;
task = new PostResponseAsyncTask(Registrados_HassMovil.this);
task.execute(url_mostrarinformacion+"?fecha="+registro.getText().toString()+"&huerto="+huerto.getText().toString());
  

Here the problem does not accept words with space ie    orchard = hello world

@Override
    public void processFinish(String s) {
        String Estado;
        try {
            JSONArray jsonArray = new JSONArray(s);
                    for (int i = 0; i < jsonArray.length(); i++) {
                        Informacion.putExtra("id", (jsonArray.getJSONObject(i).getString("id")));
                    }
                    startActivity(Informacion);
                    finish();
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

When it's a simple word, it's the part of the url where I get the orchard parameter hello up there all right but if I send hello world does not return anything to me for the space that there is. Any solution?

    
asked by DoubleM 10.01.2017 в 09:18
source

2 answers

2

URLs do not accept spaces, as well as other characters. In URLs they become special characters. You could use the class URLEncoder

 try{
    String q = "hola mundo";
    String url = "http://prueba.com/consulta?q=" + URLEncoder.encode(q, "UTF-8");
 } catch (UnsupportedEncodingException ex) {
    ex.printStackTrace();
 }
    
answered by 10.01.2017 в 10:15
0

That is an error that can happen in any language. If you are going to send information in the "query string" you have to escape the special characters and spaces. For example, spaces must be replaced by the + sign. But it would be convenient that you do not do it by hand and look for the way to do it with the libraries that you are using.

    
answered by 10.01.2017 в 10:10