The problem is that the programme does send the XML to the target system, however the target is returning a result that is indicates an error;
<?xml version="1.0" ?>
<errormsg>XML text was Empty. Sorry, you have submitted an empty form</errormsg>
According to the administrator of the target system, the error is due to the fact that the something in my HTTP message(the envelope must I presume) must conform to the name attribute of the textarea element in his php form. He even gave me a fragment of his code:
Input name: “xmldata”
This is the first time I am working with a code that requires me to interface with a php based system. I don't even know what I assumed above is correct in fact I don't know PHP. Please help. If any of the info is not clear please let me know.I will feedback ASAP. Really urgent. Thank you all in advance.
The code I have used is the general code that is used to POST xml messages across the system in my company. However for this interface, the request is quite different. In fact this is the first time I am looking at the codes that deal with HttpPOST. Generally the xml that is to be sent is the inputMsg String object. This is later turned into a RequestEntity object @ line 90.
RequestEntity entity = new InputStreamRequestEntity(IOUtils.toInputStream(inputMsg), contentType);
That object is later set to the PostMethod object line 91
The final stage of sending the data to the form is done by line110:
int statusCode = client.executeMethod(post);
I am not sure whether I have correctly explained as most of it was learnt recently from other websites.
I have also tried to use a small code to do the POSTing, just to test out key concepts:
But the XML in the response still indicated an error.
But there would always be error thrown by the Compiler, I guess it has something to do with the special characters. I "". . I know that we have to use escape character and so I have modified the xmlData string to contain escape characters.
String xmlData = "<?xml version = \"1.0\" encoding = \"utf-8\"?>"+"<data>"+"<ordernum>1-J0K0Y</ordernum>"+"<custname>Ashwaq</custname>"+"<custname>Ashwaq</custname>"+"<mobilenum>0125598693</mobilenum>"+"<orderstatus>Submitted</orderstatus>"+"<prodtype>DEL</prodtype></data>";
Tried this as well but still the response is :
<?xml version="1.0" ?><data><errorcode>1</errorcode><errormsg>XML text was Empty. Sorry, you have submitted an empty form</errormsg></data>
I have to catch a train. See you later. Thanks for you help. Will login later tonight. Thanks again.
Check the code below which I wrote and I got response as "<html><head><title>504 Gateway Timeout</title></head><body><h1>Gateway Timeout</h1>
<p>Server error - server 184.108.40.206 is unreachable at this moment.<br><br>Please retry the request or contact your adminstrator.<br></p>
Just see if this helps. I've used HttpClient-4.1.2.
Sorry for not replying to you all for a long time I managed to find the answer but only now did i have the time to post the solution to the problem. What I understand from this problem is that we are trying to write a programme that would mimic a standard HTML form that would POST data to server. As you would remember a HTML form will contain text areas, checkbox, radio button, SELECT tags and so on just like below:
The key is to mimic the textarea element. I tried to see how the for would be sending the data in the textarea element. To do that try opening the form in FireFox. and run HttpFox, and click submit.
You will find that the data sent out was :
So we have to create a name-value pair and send it as a data , the name being xmldata, value being the xml .
That was achieved via :
The data sent out was just like as it was sent out from the form.
The following lines were added :
As they would enable debugging the http message. This is not the only method, there are a lot of methods and ways to post data through Java programme. i don't have time to go through them all hence my simple unelegant methodology. Feel free to add more of your suggestion or better way. Thank you Naren Mane and Tim Moores for replying.
Police line, do not cross. Well, this tiny ad can go through: