Send post data to server using Volley android

后端 未结 5 1520
情话喂你
情话喂你 2021-02-10 04:08

I am trying to send some data to the server using the Volley library.

   private void registerUser(final String email, final String username,
                            


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-10 04:48

    requestQueue= Volley.newRequestQueue(MainActivity.this);
    StringRequest request=new StringRequest(Request.Method.PUT, url, new Response.Listener() {
        @Override
        public void onResponse(String response) {
            Toast.makeText(MainActivity.this, ""+response, Toast.LENGTH_SHORT).show();
            Log.d("response",response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
    
        }
    }){
        @Override
        protected Map getParams() throws AuthFailureError {
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("name", name.getText().toString().trim());
                jsonObject.put("email", email.getText().toString().trim());
                jsonObject.put("phone", phone.getText().toString().trim());
            } catch (JSONException e) {
                e.printStackTrace();
            }
    
            Map params = new HashMap();
            params.put("message", jsonObject.toString());
    
            return params;
        }
        };
    requestQueue.add(request);
    

    [["deep","dee@gmail.com","8888999999"]]

提交回复
热议问题