Send POST request with JSON data using Volley

JsonObjectRequest actually accepts JSONObject as body. From this blog article, final String url = “some/url”; final JSONObject jsonBody = new JSONObject(“{\”type\”:\”example\”}”); new JsonObjectRequest(url, jsonBody, new Response.Listener<JSONObject>() { … }); Here is the source code and JavaDoc (@param jsonRequest): /** * Creates a new request. * @param method the HTTP method to use * @param url … Read more

How to POST raw whole JSON in the body of a Retrofit request?

The @Body annotation defines a single request body. interface Foo { @POST(“/jayson”) FooResponse postJson(@Body FooRequest body); } Since Retrofit uses Gson by default, the FooRequest instances will be serialized as JSON as the sole body of the request. public class FooRequest { final String foo; final String bar; FooRequest(String foo, String bar) { this.foo = … Read more