Send POST request with JSON data using Volley

前端 未结 8 690
梦谈多话
梦谈多话 2020-11-22 12:07

I would like to send a new JsonObjectRequest request:

  • I want to receive JSON data (response from server): OK
  • I want to send JSON form

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 12:41

        final String url = "some/url";
    

    instead of:

        final JSONObject jsonBody = "{\"type\":\"example\"}";
    

    you can use:

      JSONObject jsonBody = new JSONObject();
        try {
            jsonBody.put("type", "my type");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    new JsonObjectRequest(url, jsonBody, new Response.Listener() { ... });
    

提交回复
热议问题