1

I want to add authorization header in android volley library , But unfortunately I am getting errors "BasicNetwork.performRequest: Unexpected response code 400"

I have tried many suggestions but it didn't work. Please help me to sort out this issue. Thanks.

 private void getLogin() {
            final ProgressDialog mProgressDialog = new ProgressDialog(getActivity());
            mProgressDialog.setMessage("Please wait...");
            mProgressDialog.show();

            RequestQueue mRequestQueue = Volley.newRequestQueue(getActivity());
            StringRequest sr = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.print("Login Response", "" + response);
                    mProgressDialog.dismiss();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    Toast.makeText(getActivity(), volleyError.getMessage(), Toast.LENGTH_LONG).show();
                }
            }) {
                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> paramsValue = new HashMap<String, String>();
                    paramsValue.put("username", new String(username));
                    paramsValue.put("password", new String(password));
                    paramsValue.put("grant_type", new String(grant_type));
                    return paramsValue;
                }

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("Authorization", "Basic ZGVtb01vYmlsZUNsaWVudDpwYXNzd29yZDE=");
                    return params;
                }
            };
            sr.setRetryPolicy(new DefaultRetryPolicy(
                    999999999,
                    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

            mRequestQueue.add(sr);
        }

Volley Library:

 com.mcxiaoke.volley:library:1.0.19
Bhumit
  • 338
  • 3
  • 12

0 Answers0