Posting Data on server Using Volley Android This Tutorial let us know how to post data using volley. Here i will be calling a POST service which will accept parameters and returns a json result . This is method we will be using to add parameters which we want to send to server.

  try {

                        StringRequest stringRequest = new StringRequest(Request.Method.POST, Scan_URL,
                                new Response.Listener<String>() {
                                    @Override
                                    public void onResponse(String response) {
                                        getJsonResponse(response);
                                        System.out.println("RESPONSE" + response);
                                    }
                                },
                                new Response.ErrorListener() {
                                    @Override
                                    public void onErrorResponse(VolleyError error)
                                    {
                                        Toast.makeText(QRScan_Activity.this, error.toString(), Toast.LENGTH_LONG).show();
                                    }
                                }) {
                            @Override
                            protected Map<String, String> getParams()
                            {

                                Map<String, String> params = new HashMap<String, String>();
                                params.put("UserID", strUserId);
                                params.put("UserQRCode", Data);
                                params.put("QRLAt",sessionManager.getCurrentLat());
                                params.put("QRLong",sessionManager.getCurrentLong());

                    return params;
                            }
                        };

                        RequestQueue requestQueue = Volley.newRequestQueue(this);
                        requestQueue.add(stringRequest);


                    } catch (Exception e) {
                        e.printStackTrace();
                    }

Leave a comment