Curl 请求损坏 XML Post 数据
我使用 curl 将 XML 数据作为 POST 请求发送到服务器,如下所示:
// $params contains xslt="<xml version ...."
$url = get_cfg_var('Http_Host') . "/webservice/update.php?";
$strParameters = http_build_query($params);
$ch = curl_init($url);
// Set options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strParameters);
$data = curl_exec($ch);
现在,当我在 webserive/update.php 中获取数据时
$_REQUEST['xslt']
仅包含来自 xml 的一些叶数据大多数标签都像这样被删除了[但有很多新行]
USD
,
.
0
5
我不知道发生了什么。这是双重编码问题吗?
strParameters 确实包含表单 urlencoded 格式的正确数据 [+ 表示空格等]
在将其发送到curl 之前我尝试了 urldecode。但它仍然没有解决问题。
I am sending XML data as a POST request with curl to server as follows:
// $params contains xslt="<xml version ...."
$url = get_cfg_var('Http_Host') . "/webservice/update.php?";
$strParameters = http_build_query($params);
$ch = curl_init($url);
// Set options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strParameters);
$data = curl_exec($ch);
Now when I get the data in webserive/update.php
$_REQUEST['xslt']
contains only some leaf data from xml with most of the tags stripped out like so [but with a lot of new lines]
USD
,
.
0
5
I am at a loss to understand what is happening. Is it some double encoding issue?
strParameters does contain proper data in form-urlencoded format [+ for space etc.]
I tried a urldecode before sending it to curl. but it still doesn't solve the issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这更多的是一个评论,而不是一个具体的解决方案,但我会考虑使用数组方法而不是自己编码:
您不需要自己对后数据进行编码。可以直接使用数组,参见:
This is more a comment than a concrete solution, but I would consider to use the array method instead of encoding your own:
You don't need to encode the post-data yourself. You can directly use an array, see: