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

发布于 2024-11-19 00:28:08 字数 653 浏览 3 评论 0原文

我正在将一串 XML 标签和 PHP 数据发送到另一台需要 XML 的服务器上的 API。

我们通过命令行发送字符串,就像这样

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

$xml 是发送到 API 的标签字符串和 pringoperties。

API 将字符串精细处理为 XML 并返回响应。但是,包含返回的成功或失败 xml 的 $response 将作为不包含任何 XML 标记的数组发送回。

不幸的是,我们以字符串形式发送数据,因为服务器运行的是没有 domxml 扩展的 PHP 4.3.9,也没有安装 PHP curl。我们无法在另一台服务器上运行它,并且由于服务器上运行其他软件,我们无法升级服务器。

因此,由于我们需要使用此 API,因此我们认为可以将 XML 作为字符串发送(这似乎工作正常),但我们得到的响应并不是以字符串或 xml 的形式返回。

我们知道 API 服务器在记录每个请求时返回 XML,并且我们可以在其日志中看到输入文档和返回的响应。

不知怎的,命令行curl似乎正在将XML响应更改为不带标签的数组。

我希望这是有道理的。有谁知道如何获取 XML 响应,以便我们可以成功检索数据。

I'm sending a string of XML tags and data in PHP to an API on another server that is expecting XML.

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.

The API processes the string to XML fine and returns a response. 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.

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. 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.

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.

Somehow it seems command line curl is changing the XML response to an array without tags.

Im hoping this makes some sense. Does anyone know away to get the XML reponse so we can retrieve the data successfully.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆伤 2024-11-26 00:28:08

我们找到了解决这个问题的办法。我仍然不确定为什么返回的响应是一个数组而不是一个字符串,但设法让它在数组元素中包含标签。然后,我们使用 foreach 循环将数组的每个键传递到字符串的末尾。

然后我们就得到了我们想要的响应。

抱歉,我知道如果没有例子,任何人都很难提供帮助,尤其是当问题不清楚时。事实证明,这是其中一种情况,您只需要使用代码,直到获得您想要的解决方案。

不管怎样,非常感谢您花时间阅读这篇文章。

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文