Help with post request in java

0

Hello.

I'm trying to call a php webservice via post using java. the code and the following:

public void post(String json) {
        try {
            CloseableHttpClient client = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost("http://localhost:1111/WS/pdf/v1/boleto");
            StringEntity entity = new StringEntity(json);
            httpPost.setEntity(entity);
            httpPost.setHeader("Content-type", "application/json");
            HttpResponse response = client.execute(httpPost);
            System.out.println(EntityUtils.toString(response.getEntity()));
            client.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

As parameter json I pass a json that is converted using GSON that takes my object and transforms it into JSON.

The problem is that I can not handle the json I get in php.

My code:

$json = file_get_contents('php://input');
echo json_decode($json);

I can make it read if I pass json right into the code:

StringEntity entity = new StringEntity("{\"nome\": \"Teste\"}");
    
asked by anonymous 17.04.2018 / 19:16

0 answers