I have the following code in my java client
HttpPost httpPost = new HttpPost("http://localhost:8888/user/mick");
httpclient.execute(httpPost);
List<String> formparams = new ArrayList<String>();
formparams.add("John");
formparams.add("Doe");
StringEntity entity = new StringEntity("important message", "UTF-8");
String contentType = "application/text";
httpPost.setHeader("Content-Type", contentType);
httpPost.setHeader("Accept", contentType);
httpPost.setEntity(entity);
try {
// execute the request
httpclient.execute(httpPost);
}
catch (Exception e) {
e.printStackTrace();
}
the first POST hits the server ok so this proves comms are working.
However, the second one does not hit the server and does not throw any exceptions either. It seems that if I remove the line that adds the entity
ie httpPost.setEntity(entity);
then the POST reaches the server but the request contains no data.
So what I would like to see is a worked example that sends a java String from client to server but contained within a POST. I have no prob with a solution where I send a string using GET but I want to use POST.
I would have thought this should be a simple task but it's starting to look anything but simple.
Any help would be appreciated :)