Page 1 of 1

handling XML sent via http:

Posted: Sat Feb 25, 2012 12:48 pm
by greynolds
Hi,
I’m trying to write a PHP page that receives XML from a remote sever (triggered by a third party event such as a message being sent to the server.) Thus, I am not querying a server and processing a response, but rather waiting for a unsolicited (but not unwelcome) call to my page.

If I have the XML in a local file, I can process the XML just fine with:
$url = 'xml-file.xml';
$xml = simplexml_load_file($url);

Btw the xml in the file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<ALERTSERVICE>
<PHONENUMBER>1234567890</PHONENUMBER>
<KEYWORD>Traffic</KEYWORD>
<CONTENTS>Route 42</CONTENTS>
</ ALERTSERVICE >

Can anyone provide with the code substitution for when the same XML is contained in the HTTP, like this:
http://www.some_server.com/process_test/process.php?xml=<?xml version="1.0" encoding="UTF-8"?><ALERTSERVICE><PHONENUMBER>1234567890</PHONENUMBER><KEYWORD>traffic</KEYWORD><CONTENTS>Route 42</CONTENTS></ALERTSERVICE>

I have the feeling that I’m missing something totally obvious, but have been fruitlessly searching and experimenting, up against a deadline. Thanks in advance for your help!

Re: handling XML sent via http:

Posted: Sat Feb 25, 2012 5:06 pm
by Eric!
This seems a bit sketchy to be passing XML in the URL query, but this is how you would get the xml in your example

Code: Select all

$xml=$_GET['xml']; // read into a string ... you might want to filter this string some depending on what you are doing with it
//now convert it to an xml object and process it.
You might need to urldecode() it too...