How to receive xml requests and send response xml in php? How to receive xml requests and send response xml in php? xml xml

How to receive xml requests and send response xml in php?


The general idea is to read in the POST value, parse it as XML, make a business decision on it, build out an XML response according to the API you've decided on, and write it into the response.

Read in the POST value:

$dataPOST = trim(file_get_contents('php://input'));

Parse as XML:

$xmlData = simplexml_load_string($dataPOST);

Then, you would build out an XML string (or document tree, if you wish), and print it out to the response. print() or echo() will do fine.


All you have to do on the receiving end is create a 'normal' PHP script. Depending on the protocol between your endpoint and the requesting service you need to grab the data from the correct location which is most likely going to be a $_GET or $_POST array.

You may have to read the raw POST data if it's not coming through in $_POST, take a peak at this article

http://www.codediesel.com/php/reading-raw-post-data-in-php/