I am trying to post some parameters to my rails API using Volley in Android. This is the code:
I tried with two log statements, one in getParams() and
To provide POST parameter build a JSONObject with your POST parameters and pass that JSONObject as a 3rd parameter. JsonObjectRequest constructor accepts a JSONObject in constructor which is used in Request Body.
JSONObject paramJson = new JSONObject();
paramJson.put("key1", "value1");
paramJson.put("key2", "value2");
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,url,paramJson,
new Response.Listener() {
@Override
public void onResponse(JSONObject response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);