0

I have Url for Login. Its working and give response in Postman and Retrofit but not working with volley.

In volley its give error: com.android.volley.RedirectError

Why i geeting RedirectError. url working and give response in retrofit as well in postman.

Here is my Code:

  public void Login(){

    final String REGISTER_URL = "Here_My_Url";


    StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    Log.d("onResponse", response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("eee123",error.toString());
                    Toast.makeText(getApplicationContext(), error.getMessage(), 
    Toast.LENGTH_SHORT).show();
                }
            }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("user_email", st_email);
            params.put("password", st_pass);

            Log.e("params", " " + params);


            }
            return params;
        }


        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = new HashMap<>();

            headers.put("Content-Type", "application/json");


            return headers;
        }
    };
    stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, -1, 
    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    stringRequest.setShouldCache(false);
    VolleySingleton.getInstance(this).addToRequestQueue(stringRequest);

}
Darshi
  • 3
  • 1
  • The RedirectError is just an indicator that the server sent a 30x redirect response. Get the response, check the location hader and use it for a new request: https://stackoverflow.com/a/45973311/150978 – Robert May 07 '20 at 16:14
  • i used your suggestion @Robert , Url Redirect to unknown url , Why its redirected? – Darshi May 07 '20 at 16:22
  • Don't ask me. The server decides when to send a HTTP 30x response. It therefore depends on the request URL. May be you are using an old or outdated url? In some cases you may always get a redirect response. This is just the how the server works. – Robert May 07 '20 at 16:27

0 Answers0