Send POST request with JSON data using Volley

前端 未结 8 625
梦谈多话
梦谈多话 2020-11-22 12:07

I would like to send a new JsonObjectRequest request:

  • I want to receive JSON data (response from server): OK
  • I want to send JSON form

8条回答
  •  逝去的感伤
    2020-11-22 12:57

    final Map params = new HashMap();
            params.put("email", customer.getEmail());
            params.put("password", customer.getPassword());
            String url = Constants.BASE_URL+"login";
    
    doWebRequestPost(url, params);
    
    
    public void doWebRequestPost(String url, final Map json){
            getmDialogListener().showDialog();
    
        StringRequest post = new StringRequest(Request.Method.POST, url, new Response.Listener() {
            @Override
            public void onResponse(String response) {
                try {
                    getmDialogListener().dismissDialog();
                    response....
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(App.TAG,error.toString());
                getmDialogListener().dismissDialog();
    
            }
        }){
            @Override
            protected Map getParams() throws AuthFailureError {
                Map map = json;
    
                return map;
            }
        };
        App.getInstance().getRequestQueue().add(post);
    
    }
    

提交回复
热议问题