Volley JsonObjectRequest Post request not working

后端 未结 9 1943
有刺的猬
有刺的猬 2020-11-22 06:25

I am using android Volley for making a request. So I use this code. I don\'t understand one thing. I check in my server that params is always null. I consider that getParams

9条回答
  •  春和景丽
    2020-11-22 07:03

    When you working with JsonObject request you need to pass the parameters right after you pass the link in the initialization , take a look on this code :

            HashMap params = new HashMap<>();
            params.put("user", "something" );
            params.put("some_params", "something" );
    
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, "request_URL", new JSONObject(params), new Response.Listener() {
            @Override
            public void onResponse(JSONObject response) {
    
               // Some code 
    
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //handle errors
            }
        });
    
    
    }
    

提交回复
热议问题