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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With