简体   繁体   English

创建 php xml 侦听器和侦听器。在响应 XML 时遇到问题

[英]Creating php xml listener and listening.Having trouble in responding back an XML

I am using a third party API in the system which post xml data to my URL which I get and process the xml.我在系统中使用第三方 API,它将 xml 数据发布到我获取并处理 xml 的 URL。 They are saying server has to reply back as Accepted.他们说服务器必须回复为已接受。 I am having trouble in this part.我在这部分遇到了麻烦。

Example:例子:

if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
{
    //Read the xmlinput and write to the file
    $xml = file_get_contents('php://input');
   //...processing the xml and storing to my SQL...

   //How to reply back as '<xml>Accepted</xml>'

}

Please need help.I am able to process xml file and get the data but having sending them back xml reply.请需要帮助。我能够处理 xml 文件并获取数据,但已将它们发回 xml 回复。

Note:API post results to URL.注意:API 将结果发布到 URL。 My server should respond with "Accepted" if successful如果成功,我的服务器应该响应“已接受”

header("Content-type: text/xml");
$dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->createElement('xml', 'Accepted');
$dom->appendChild($element);
echo $dom->saveXML();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM