Skip to main content

Reading Body Content

1 reply [Last post]
Joined: 2008-06-23
Points: 0


I am bit of a bother here, hope some one might be able to help.

I have a struts application, in which I am being hit at a particular action url say (https://localhost/apolloweb/billing/,

Now at this action I want to read the body content, it was supposed to be in xml form but i have no idea how to read the request content.

I also have to send some xml data to a particular url, which I have achieved through this code:

post = new PostMethod(directoryUrlToPost);
post.setRequestHeader("Content-type", "text/xml");
post.setRequestHeader("Authorization", "Basic HGTFSas);
post.setRequestHeader("Host", "");
post.setRequestHeader("Content-Length", "11420");
post.setRequestHeader("Expect", "100-continue");
HttpClient client = new HttpClient();
int result = client.executeMethod(post);
strXMLResponse = post.getResponseBodyAsString();
logger.debug("Response from Sure Script: " );
logger.debug(strXMLResponse );

I have not tested this code but I think it will work, Now the receiver of this message will be sending the response of this data
Back to me in the same way as I am doing above.

Now could any body help me out how to read out the xml when a certain request hit your server like the above code is.

Many thanks in advance.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-06-23
Points: 0

Able to find the solution my self , it is as simple is this:

BufferedReader brrr = request.getReader();
String s;
StringBuffer req_message = new StringBuffer();
while((s = brrr.readLine()) != null)

Now req_message will hold all the body content(s).