Unexpected response code 500 for POST method

The problem is below.

final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
    Method.POST,
    act.getString(R.string.CommentForUserURL),
    null, new Response.Listener<JSONObject>() {
    ^^^^

It should be

final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
    Method.POST,
    act.getString(R.string.CommentForUserURL),
    new JSONObject(params), new Response.Listener<JSONObject>() {
    ^^^^^^^^^^^^^^^^^^^^^^

Copy code from protected Map<String, String> getParams() before final JsonObjectRequest.

That’s it!!!

Reason is as below.

The JsonObjectRequest is extended JsonRequest which override getBody() method directly, so your getParam() would never invoke, I recommend you extend StringRequest instead of JsonObjectRequest.

your can check this answer for more details.

Leave a Comment