How to post request parameters when using JsonArrayRequest in Volley

后端 未结 5 1503
暗喜
暗喜 2020-12-06 22:03

I am newbie to Json parsing. I am trying to read a json data using JsonArrayRequest but I am little confused in sending parameters and use POST method.In case o

5条回答
  •  不知归路
    2020-12-06 22:43

    here is an example to post the request to the server using volly

    You can add the parameters to a HashMap and then pass that into the request you are creating;

    EDITED:

        HashMap mRequestParams = new HashMap();
        mRequestParams.put("username","abcd");
        mRequestParams.put("password", "123456");
    
        public void vollyStringRequestForPost() {
    
    
       JsonArrayRequest req = new JsonArrayRequest(Request.Method.POST, strURL, new JSONObject(mRequestParams),
                    new Response.Listener() {
    
                        @Override
                        public void onResponse(JSONArray response) {
    
                                try {
    
                                   //Here you will receive your response
    
                                } catch (JSONException e) {
    
                                    e.printStackTrace();
    
                                }
                            }
                        }, new Response.ErrorListener() {
    
                    @Override
                    public void onErrorResponse(VolleyError error) {
    
                        //Do what you want to do on error
                    }
                });
    
    
    
            mRequestQueue.add(req);
        }
    
    
    }
    

提交回复
热议问题