【发布时间】:2021-09-01 13:54:03
【问题描述】:
作为前言:我无法想象以前没有人问过这个问题,但是我在寻找解决方案时惨遭失败......我认为有一个简单的解决方案,我只是在做完全错误的事情。
我有一个简单的 index.php 文件,看起来像这样:
<?php
$data = file_get_contents('php://input');
echo "DATA : " . $data;
$xml = new SimpleXMLElement($data, 0, true);
echo "XML : " . $xml;
$RoundTrip = (string) $xml->RoundTrip;
$TransactionId = (string) $xml->TransactionId;
?>
回显“DATA”显示:
<?xml version="1.0" encoding="utf-8"?><msg><head><Client>Test</Client><RoutingArea>811</RoutingArea><Source>MySRC</Source><Destination>BSRC</Destination><Version>2.27</Version><RoundTrip>ID=001088129291102</RoundTrip><TransactionId>12652b05-ceb9-11eb-a091-00505687f2ee</TransactionId><ServerId>03</ServerId></head><body><POdated>
...SimpleXMLElement 抛出错误:
PHP Warning: SimpleXMLElement::__construct(): I/O warning : failed to load external entity "<?xml version="1.0" encoding="utf-8"?><msg><head
好像字符串被读取为 URLencoded...但初始输出不是 URLencoded。
我的目标是:从请求中以字符串形式接收 XML 文档并能够对其进行解析。
【问题讨论】:
-
通过查看实际源代码来检查您的原始字符串是否被浏览器格式化。
-
@NigelRen 我没有在浏览器中执行任何这些操作。这一切都在服务器上。谢谢!
标签: php xml xmlhttprequest