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

前端 未结 2 864
别跟我提以往
别跟我提以往 2021-02-01 21:14

So I need to build an application that will receive xml request and based on that I will have to return the response xml. I know how to send requests and receive the response, b

2条回答
  •  春和景丽
    2021-02-01 21:47

    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.

提交回复
热议问题