Problem receiving data by GET on android

private static PostResponseAsyncTask task;
task = new PostResponseAsyncTask(Registrados_HassMovil.this);

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

    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")));
        } catch (JSONException e) {


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

2 answers


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

    String q = "hola mundo";
    String url = "" + URLEncoder.encode(q, "UTF-8");
 } catch (UnsupportedEncodingException ex) {
answered by 10.01.2017 в 10:15

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