Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Client not sending POST request to server

823838Jun 8 2011 — edited Jun 10 2011
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 :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 8 2011
Added on Jun 8 2011
13 comments
841 views