Post Method using Volley not working

前端 未结 5 1031
天命终不由人
天命终不由人 2020-12-06 19:32

Hi i am using Volley for my login page. I need to pass data like this manner

{
userID : \'-988682425884628921\',
email :\'aditya@vyas.com\',
pas         


        
5条回答
  •  隐瞒了意图╮
    2020-12-06 20:31

    i have same problem use this :

            StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
                new Response.Listener() {
                    @Override
                    public void onResponse(String response) {
                        Toast.makeText(LoginActivity.this, response, Toast.LENGTH_LONG).show();
    
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(LoginActivity.this, error.toString(), Toast.LENGTH_LONG).show();
    
                    }
                }) {
    
            @Override
            public Map getParams()  {
                HashMap headers = new HashMap();
                headers.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
                headers.put("UN", UserName);
                headers.put("PW", PassWord);
                return headers;
    
    
            }
    
        };
    
        RequestQueue requestQueue = Volley.newRequestQueue(this);
         requestQueue.add(stringRequest);
    

    Just need to add headers.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); to parms

    good luck.

提交回复
热议问题