Map<String, String> params = new HashMap<String, String>(); params.put("fromUser", "lesliefang"); params.put("toUser", "xiaojun"); JsonObjectRequest newMissRequest = new JsonObjectRequest( Request.Method.POST, "http://127.0.0.1:8080/users", new JSONObject(params), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonobj) { } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } });
volley 将 200 201 等视为成功的请求,而将 204 400 404 等视为失败的请求,会回调到 ErrorListener 中。