简体   繁体   English

curl 命令行返回的格式错误的 XML

[英]malformed XML returned by curl command line

I'm sending a string of XML tags and data in PHP to an API on another server that is expecting XML.我正在将 PHP 中的一串 XML 标签和数据发送到另一台服务器上的 API,该服务器期望 Z3501BB7093D9B6CFED305501BB093D39CFED30

we are sending the string via command line like this我们像这样通过命令行发送字符串

exec("curl http://addressToAPI.com/index.php?xml=$xml", $response);

$xml is the string of tags and pringoperties were sending to the API. $xml 是发送到 API 的标签字符串。

The API processes the string to XML fine and returns a response. API 将字符串处理为 XML 并返回响应。 However the $response which contains the returned success or failure xml is sent back as an array which doesnt include any of the XML tags.但是,包含返回的成功或失败 xml 的 $response 作为不包含任何 XML 标记的数组发送回。

Unfortunately we are sending the data as a string because the server is running PHP 4.3.9 without domxml extension and doesnt have PHP curl installed either.不幸的是,我们将数据作为字符串发送,因为服务器正在运行没有 domxml 扩展的 PHP 4.3.9 并且也没有安装 PHP curl。 We cannot run it on another server and we cant upgrade the server due to other software running on it.我们无法在另一台服务器上运行它,并且由于在其上运行其他软件,我们无法升级服务器。

So since we need to work with this API we figured we could send the XML as a string (which seems to work fine) but its the response we get back just isn't returned as a string or xml.因此,由于我们需要使用此 API,我们认为我们可以将 XML 作为字符串发送(这似乎工作正常),但我们返回的响应不是作为字符串或 Z0F635D0E0F3872E6FFF8B581CA.3

We know the API server is returning XML as it logs every request and we can see the input document and returned response in its log.我们知道 API 服务器正在返回 XML,因为它记录了每个请求,我们可以在其日志中看到输入文档和返回的响应。

Somehow it seems command line curl is changing the XML response to an array without tags.不知何故,命令行 curl 似乎正在将 XML 响应更改为没有标签的数组。

Im hoping this makes some sense.我希望这是有道理的。 Does anyone know away to get the XML reponse so we can retrieve the data successfully.有谁知道得到 XML 响应,以便我们可以成功检索数据。

We figured out a solution to this.我们想出了一个解决方案。 Im still unsure why the returned response is an array rathan just a string but managed to get it to include the tags in the array elements.我仍然不确定为什么返回的响应是一个数组而不是一个字符串,但设法让它包含数组元素中的标签。 We then use a foreach loop to pass each key of the array onto the end of a string.然后,我们使用 foreach 循环将数组的每个键传递到字符串的末尾。

We then have the response we wanted.然后我们得到了我们想要的响应。

Apologies, I understand its hard for anyone to help without examples, especially when the problem isnt clear.抱歉,我理解任何人都很难在没有示例的情况下提供帮助,尤其是在问题不清楚的情况下。 It turned out to be one of them cases where you just needed to play with the code until you got the solution you wanted.事实证明,这是其中一种情况,您只需要使用代码,直到获得所需的解决方案。

Either way many thanks for your time in reading this post.不管怎样,非常感谢您花时间阅读这篇文章。

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

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