0

I'm sending post request for login user on server through volley string request. It works perfectly but the problem is that after sending request server returns me two responses one is success in which token id is given and the other one is failure in which unauthorized user is toast. Im getting the response perfectly but can use check to differentiate these responses. Kindly someone helps me Im very thakful to you.

I'm trying many times but can't get the exact solution.

 RequestQueue queue = Volley.newRequestQueue(this);
            String url =LOGIN_URL;
            final StringRequest strRequest = new StringRequest(Request.Method.POST, url,
                    new Response.Listener<String>()
                    {
                        @Override
                        public void onResponse(String response)
                        {
                            Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
                        }
                    },
                    new Response.ErrorListener()
                    {
                        @Override
                        public void onErrorResponse(VolleyError error)
                        {
                            Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
                        }
                    })
            {
                @Override
                protected Map<String, String> getParams()
                {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("grant_type", grant_type);
                    params.put("client_id", client_id);
                    params.put("client_secret", client_secret);
                    params.put("username", email);
                    params.put("password", password);

                    return params;
                }
            };

            queue.add(strRequest);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mughira Dar
  • 103
  • 1
  • 1
  • 6
  • Your intention is not clear. Please add sample response and tell what you want to do exactly. – The_ehT Nov 12 '19 at 11:36
  • @Override public void onResponse(String response) { Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show(); } – Mughira Dar Nov 12 '19 at 11:50
  • Check this https://stackoverflow.com/a/24700973/1517029 – The_ehT Nov 12 '19 at 11:52
  • When i send request to server , server returns me response which i toast in code given above . But i want to use check here because i have two types of responses that i get from server . e.g if( response.getString("success") ){} else if (response.getString("invalid")){} – Mughira Dar Nov 12 '19 at 11:53

0 Answers0