PHP RESTful API访问Jersey客户端POST数据

I am using a PHP RESTful API which is consumed by a Java desktop application using jersey 2.21.

Usually, when I send a POST request from AngularJS, I can access the data via:

$data = json_decode(file_get_contents("php://input"));

However, when I use jersey, the data is put in the $_POST array. Here is my Jersey code:

final HashMap<String, String> params = // some hashmap with a few entries
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
MultivaluedMap formData = new MultivaluedHashMap(params);

WebTarget target = client.target(url);


// Get JSON
String jsonResponse = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);

return jsonResponse;

How do I post the data from Jersey so that I can access it via the above PHP call?

I know I can just use the $_POST array, but I need this API to be consumed from a mobile app, Java desktop & an AngularJS app.

Thanks in advance

Thanks to @jonstirling, I got it.

I had to set the content type as JSON. here is the updated code:

ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);

WebTarget target = client.target(url);

String data = new Gson().toJson(params);

// POST JSON
Entity json = Entity.entity(data, MediaType.APPLICATION_JSON_TYPE);
Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON_TYPE);
String jsonResponse = builder.post(json, String.class);

return jsonResponse;