[Solved] In volley library giving

I try to login in my application, when I try to call API using volley library, it’s giving and response code 400.

final String username = editTextUsername.getText().toString().trim();
        final String password =   editTextPassword.getText().toString().trim();
        final String email = editTextEmail.getText().toString().trim();

  StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
                new Response.Listener<String>() {
                    public void onResponse(String response) {
                new Response.ErrorListener() {
                    public void onErrorResponse(VolleyError error) {
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                params.put(KEY_PASSWORD,password);`enter code here`
                params.put(KEY_EMAIL, email);
                return params;


        RequestQueue requestQueue = Volley.newRequestQueue(this);

I saw the many examples but I did not get any solution.

Solution #1:

I had the same issue. It drained my entire day. Finally, I Found the tiny error, which was that I was passing a null value in parameters.

Check if you are passing a null value to the server in getParams() or your JSON Object. If yes, that may be the problem.

Respondent: Umasankar

Solution #2:

In below method

public void onErrorResponse(VolleyError error)

add this line:-


You will get all stack trace which gives you the actual error. I have also get this error but in my case it is actually TimeoutException.

Solution #3:

Response Code 400 means Bad Request.

Some reasons for that.

  1. There might be issue in Request method. Is it GET or POST.
  2. API might be expecting Authorization Header.
Respondent: Code-Warrior

Solution #4:

This error can mean BAD REQUEST, check the headers you are sending. Overring the getHeaders() method you can send the right headers.

public Map<String, String> getHeaders() throws AuthFailureError {
        return (headers != null || headers.isEmpty()) ? headers : super.getHeaders();

Also, usually the WebServices need application/json headers, as follow:

Respondent: Alejandro Traver

Solution #5:

What causes this error…
1.Wrong Url,check your url for any errors.
2.Missing parameters,any parameters is having null value or you are missing any parameter.
3.Watch for the Keys defined in the params,it should match with those of APIs.
Hope it helps!

Respondent: Sachin Soma

Solution #6:

You have to have a same Method in your java codes and in the php codes . you defined “POST” method for your request with volley library to server , now you have to have “POST” method in your php files at your server for giving the request .

Respondent: ??? ?????????

Solution #7:

You may also need to tell your server that send the response with the code 200, volley checks for this codes.

Respondent: Pianisimo

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy