Error using Volley in Android Studio

0

Hello as I understand to send a url to a web service parameters are used to use them in the query to the database. But in the case of wanting to bring everything from a table and not send parameters how would the JsonObjectRequest be used? Thank you.

String url = "http://192.168.0.69/webservice/comercios.php";

jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, 
 null,this,this);

request.add(jsonObjectRequest);

That's where it says "POST" what would I have to say if we did not send parameters? Thanks

    
asked by Juampi 22.11.2018 в 17:53
source

1 answer

0

Only enter the url. An example

 JsonArrayRequest arrayRequest = new JsonArrayRequest(url ,         // Es con un json array request y se indica el url
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    if (response.length() > 0) {                         
                        for (int i = 0; i < response.length(); i++) {
                            try {
                                JSONObject data = response.getJSONObject(i);   // luego pasa a json object
                                TuPojo item = new TuPojo();                    // obtienes tu POJO
                                item.setTitulo(data.getString("titulo"));      // y le asignas los parametros obtenidos, aquí un ej (titulo)
                                 ...                                          
                                listdata.add(item);
                                // listata es el ArrayList de TuPojo
                            } catch (JSONException e){
                               e.printStackTrace();
                            }
                            }
                            adapter.notifyDataSetChanged();
                            }
                           }, new Response.ErrorListener() ...

                   Volley.newRequestQueue(getContext()).add(arrayRequest);
    
answered by 24.11.2018 в 04:47