Android发送DELETE JSON请求

时间:2015-03-13 20:28:16

标签: android json

我想通过发送JSON请求来删除某个对象。要删除对象,我将提供food_id,我在POSTMAN上尝试它,键是food_id,值是id号,它可以工作。但是当在android中尝试时,它并不起作用。真的需要帮助!!

    RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
    String url = "http://52.10.237.82:8080/api/food";
    JSONObject obj = new JSONObject();
    try {
        obj.put("food_id","54fe3c37ad3ef6992000000b");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    JsonObjectRequest jsObjRequest = new JsonObjectRequest
            (Request.Method.DELETE, url, obj, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d("Message: ", response.toString());
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("Message: ", error.getMessage());
                }
            });
    queue.add(jsObjRequest);
}

0 个答案:

没有答案