Volley not calling getParams() for standard POST request

后端 未结 11 959
执念已碎
执念已碎 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: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() {
            @Override
            public void onResponse(JSONObject response) {
    
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
    
            }
        });
    requestQueue.add(jsonObjectRequest);
    

提交回复
热议问题