Volley not calling getParams() for standard POST request

后端 未结 11 924
执念已碎
执念已碎 2020-11-30 07:56

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

相关标签:
11条回答
  • 2020-11-30 08:16

    if you use My Singleton try this:

    MyVolley.getInstance(this).getRequestQueue().getCache().clear();
    

    Maybe you use cache on your code

    0 讨论(0)
  • 2020-11-30 08:23

    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);
    
    0 讨论(0)
  • 2020-11-30 08:24

    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

    0 讨论(0)
  • 2020-11-30 08:25

    just use requestQue.getCache().clear();

    0 讨论(0)
  • 2020-11-30 08:30

    it happened because Volley params cache.

    clean it like this

    requestQueue.getCache().clear();

    hope it's useful!

    0 讨论(0)
  • 2020-11-30 08:34

    I solved my issue by simply removing Content-Type from header :)

    0 讨论(0)
提交回复
热议问题