Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

receive xml

0 views
Skip to first unread message

Dave

unread,
Nov 20, 2009, 10:44:21 AM11/20/09
to
Gang,

I have a small php script setup to send XML via cURL as shown
below. My question is, how do I process the XML on the receiving
end. I have googled this for days and read countless posts, but they
either deal with sending the XML as a string value to a POST variable
(eg: xml=<data><asdf>qwerty</asdf></data>) or don't show the code on
the receiving end. I want to send and receive pure XML so I adjust
the headers of the cURL options to read "text/xml", but am still stuck
on how to process the request on the receiving end. It appears as
though I need to use simplexml_load_string(), but I don't know what
value to pass to it. Any help would greatly be appreciated!

Dave


SCRIPT TO SEND
---------------------------
<?php
function restPostXML($uri,$xml) {
if (! $reqCurl = curl_init()) { return -1; }
curl_setopt($reqCurl,CURLOPT_VERBOSE,0);
curl_setopt($reqCurl,CURLOPT_NOPROGRESS,1);

curl_setopt($reqCurl, CURLOPT_URL,$uri);
curl_setopt($reqCurl, CURLOPT_FAILONERROR,1);
curl_setopt($reqCurl, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($reqCurl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($reqCurl, CURLOPT_HEADER,0);
curl_setopt($reqCurl, CURLOPT_HTTPHEADER, array("Content-Type: text/
xml");
curl_setopt($reqCurl, CURLOPT_TIMEOUT, 3);
curl_setopt($reqCurl,CURLOPT_POSTFIELDS,$xml);
$reqReply = curl_exec($reqCurl);

curl_close($reqCurl);
return $reqReply;
}

$xml = "<data><asdf>qwerty</asdf></data>";
$reply = restPostXML("http://www.domain.com",$xml);
print "$reply";
?>

SCRIPT TO RECEIVE XML
---------------------------------------
<?php

// this is where I don't know what to do. Any help would greatly be
appreciated!!!

if (isset($_POST['????'])) {
$xml = simplexml_load_string(????);

print "xml loaded successfully.";
}

?>

0 new messages