1
votes

Peeps, I have some problem in understanding the working of volley library, so answer with proper material which can guide me to unobserved aspects of volley is what I am looking forward to.

  1. How does my POST parameters are bind in network request. When I send params after overriding getParams() and by sending jsonObject directly in network request I don't receive any response but some server errors.
  2. Since I am testing my backend on Postman, what postman actually does(my Observation) is it bind the params in url itself. When I copy paste the url in my android code it responds positively.

So, should I code to append my params to url or there's another way round? I have alredy tried making changes to getHeaders() but it doesn't respond too!

1

1 Answers

1
votes

You should use a JsonObjectRequest with a jsonObject containing all your params.

HashMap<String, String> params = new HashMap<String, String>();
params.put("token", "8327483274823");
JSONObject jsonObject = new JSONObject(params);

JsonObjectRequest req = new JsonObjectRequest(URL,jsonObject ,
new Response.Listener<JSONObject>() {
   @Override
   public void onResponse(JSONObject response) {
       try {
           //Do stuff here
       } catch (JSONException e) {
           e.printStackTrace();
       }
   }
}, new Response.ErrorListener() {
   @Override
   public void onErrorResponse(VolleyError error) {
       //Handle Errors here
   }
});