且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在php中接收xml请求并发送响应xml?

更新时间:2022-06-03 22:26:09

总体思路是读入 POST 值,将其解析为 XML,对其做出业务决策,根据您的 API 构建 XML 响应已决定,并将其写入响应中.

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.

读入 POST 值:

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

解析为 XML:

$xmlData = simplexml_load_string($dataPOST);

然后,您将构建一个 XML 字符串(或文档树,如果您愿意),并将其打印到响应中.print() 或 echo() 都可以.

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.