Iam using Volley library to post json array to RestApi
. But i get an error BasicNetwork.performRequest: Unexpected response code 400. I lookfor many articles Volley - Sending a POST request using JSONArrayRequest but not get any solution yet.
Here's my code,
final JSONArray jsonArray = new JSONArray();
List<User> users = UserManager.composeUsers();
jsonArray.put(users);
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, "http://192.168.137.1:8080/create", jsonArray, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d("Response: ", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error: ", error.toString());
}
}) {
@Override
public String getBodyContentType() {
return String.format("application/json; charset=utf-8");
}
};
queue.add(jsonArrayRequest);
}
In the above code List<User> user
return a java object
. I want to pass the user
object to rest service.