I would like to make a simple HTTP POST using JSON in Java.
Let\'s say the URL is www.site.com
and it takes in the value {\"name\":\"mynam
@momo's answer for Apache HttpClient, version 4.3.1 or later. I'm using JSON-Java
to build my JSON object:
JSONObject json = new JSONObject();
json.put("someKey", "someValue");
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost("http://yoururl");
StringEntity params = new StringEntity(json.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
httpClient.execute(request);
// handle response here...
} catch (Exception ex) {
// handle exception here
} finally {
httpClient.close();
}