Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,337 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,032 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Sending XML

 
Reply to this topicStart new topic

Sending XML, A way to send xml to another sever and recieve a reply

General_C
post 28 Jun, 2008 - 09:38 PM
Post #1


New D.I.C Head

*
Joined: 28 Aug, 2007
Posts: 5


My Contributions


I've been having problems with sending XML to a web service. All I know is that I send it a request with the XML and it sends me a response aka I don't know much about XML send.recieve. I am using php as the server script.

The only way I have had success encoding xml is with post encoding.

<form id='final' method='POST' action='https://domain.com/recievexml?field=someXMLdata&field2=moreXMLdata' >
<input type='submit'>
</form>

This method will work fine to pass a small amount of XML. However, larger XML data size cause the url to be too long to send. The order will get sent but the xml will be truncated (to 250 characters). I've also tried this variation that eliminates the need of the xml to be in the url.


<form id='final' method='POST'
action='https://domain.com/receivexml' >
<!-- The Url I'm sending to has no .php or .asp just a folder-->
<input name='orders' type='field1'
value='somedata' />
<input name='profile' type='field2'
value='moredata' />

<input value="submit" type='submit'>
</form>

But no data is passed. This seems like a really easy problem to solve if I could be pointed in the right direction.

Since I'm using php does anyone know if there are any commands like

$Response=sendXML("url");

And yes I am encoding all the xml using php's urlencode before I send it.



Thanks in advance.
User is offlineProfile CardPM

Go to the top of the page


baavgai
post 29 Jun, 2008 - 03:10 AM
Post #2


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,576



Thanked 44 times

Dream Kudos: 325

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


You're on the right track, but there is no "field1" type. To pass an arbitrary key value pair, try hidden.

e.g.
CODE

<form id='final' method='POST'  action='https://domain.com/receivexml' >
   <input type="hidden" name="field1" value="somedata" />
   <input type="hidden" name="field2" value="somedata" />
   <input value="submit" type='submit' />
</form>


QUOTE(General_C @ 29 Jun, 2008 - 12:38 AM) *

Since I'm using php does anyone know if there are any commands like


Take a look here: http://netevil.org/blog/2006/nov/http-post...hp-without-curl

This post has been edited by baavgai: 29 Jun, 2008 - 03:12 AM
User is online!Profile CardPM

Go to the top of the page

General_C
post 29 Jun, 2008 - 08:46 AM
Post #3


New D.I.C Head

*
Joined: 28 Aug, 2007
Posts: 5


My Contributions


So what I found was my problem was the web service expects $_GET[] data in the url to be encoded for safe use in url's, but not the $_POST[] data so to solve this problem I needed to unencode the input fields.

In code
echo "<body>
<form id='final' method='POST' action='https://doamin.com/receive_order' >
<input name='orders' type='hidden' value='".urlencode($Order->getXmlEncoding())."' />
<input name='field1' type='hidden' value='some data'/>
<input name='field2' type='hidden' value='more data'/>
<input type='submit'>
</form>";
vs

echo "<body>
<form id='final' method='POST' action='https://domain.com/receive_order' >
<input name='orders' type='hidden' value='".$Order->getXmlEncoding()."' />
<input name='field1' type='hidden' value='some data'/>
<input name='field2' type='hidden' value='more data'/>
<input type='submit'>
</form>";

Thanks for the help bagvaai.

Another note is how I got the form to post without redirecting the user.

I created an invisible iframe that submits the data in the background.

echo "<iframe style='' src='http://domain.com/sendxml.php?id=1."'></iframe>";

then the sendxml.php body had

<body onload='form.submit()'>
...form data
</body>

This post has been edited by General_C: 29 Jun, 2008 - 08:48 AM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/6/08 04:19PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month