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
if you use My Singleton try this:
MyVolley.getInstance(this).getRequestQueue().getCache().clear();
Maybe you use cache on your code
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<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);
Please override the getBody() method, and if your server can not handle JSON request parameter, you have to override the getHeaders() method to change your Content-Type.
Issue can found here: https://github.com/mcxiaoke/android-volley/issues/82
just use requestQue.getCache().clear();
it happened because Volley params cache.
clean it like this
requestQueue.getCache().clear();
hope it's useful!
I solved my issue by simply removing Content-Type from header :)