Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In volley library giving com.android.volley.ServerError

When I make a request in Volley, I'm receiving com.android.volley.ServerError and response code 400.

I'm doing something like this (generic example code):

final String param1 = "...";
final String param2 = "...";
// etc. 

StringRequest stringRequest = new StringRequest(Request.Method.POST, API_URL,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show();
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show();
            }
        }){
    @Override
    protected Map<String,String> getParams(){
        Map<String,String> params = new HashMap<String, String>();
        params.put("PARAM_1", param1);
        params.put("PARAM_2",password);
        return params;
    }

};

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);

What are possible causes for this?

like image 491
Vikas Gaurav Avatar asked Oct 06 '16 10:10

Vikas Gaurav


1 Answers

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.

like image 94
Umasankar Avatar answered Nov 15 '22 21:11

Umasankar