【发布时间】:2013-02-25 05:21:50
【问题描述】:
您好,我需要接收一个以 base64 格式编码的 xml 格式的发布数据。 我将从支付网关收到此信息。现在我得到的就是这个。我的代码创建了一个 txt 文件,但它是空的。代码有什么问题吗?输出应该是文本文件中的 xml 信封。
$body = '';
$fh = @fopen('php://input', 'r');
if ($fh)
{
while (!feof($fh))
{
$s = fread($fh, 1024);
echo $s;
if (is_string($s))
{
$body .= $s;
}
}
fclose($fh);
}
$body = base64_decode($body);
$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $body;
fwrite($fh, $stringData);
fclose($fh);
我尝试联系支付网关,他们告诉我他们收到此错误“远程服务器返回错误:(417) 预期失败。”问题可能存在于我们或他们哪里?
【问题讨论】:
-
我看错了吗? $HTTP_RAW_POST_DATA 会起作用,而不是从 php://input 填充 $body 吗?从 fopen 中删除 @ 时会出现什么错误(如果有)?
-
嗨@ChrisK 谢谢!我试过 $HTTP_RAW_POST_DATA 但它仍然是一个空白文本文件,我也尝试从 fopen 中删除 @,没有错误并且仍然是一个空白文本文件。
-
@ChrisK 我也尝试回显
$fh只是为了看看它是否包含某些内容。它显示“资源 ID #2”。
标签: php xml xml-parsing