接收帖子数据xml

时间:2013-02-25 05:21:50

标签: php xml xml-parsing

您好我需要收到一个帖子数据,该数据将以x64格式编码,并以base64格式编码。 我将从支付网关收到此信息。现在我得到的就是这个。我的代码创建了一个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)期望失败。”我们或他们在哪里存在问题?

2 个答案:

答案 0 :(得分:0)

由于您的文件返回空白,我建议您从fopen()函数的支付网关验证规范。另外,如果您正确地从它们获取数据,那么我将检查base64_decode()函数。我已经看到在实际有效载荷数据的顶部可能存在标题或其他数据的情况,这些数据会破坏base64_decode并破坏您的一天。

答案 1 :(得分:0)

看起来你正在混淆文件处理程序,你能看到以下代码是否运行:

$body = $HTTP_RAW_POST_DATA;
$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");

$stringData = $body;
fwrite($ourFileHandle, $stringData);
fclose($ourFileHandle);

我刚刚成功测试了上面的代码。

我建议你做的是尝试以下方法:

  • 尝试将一段静态数据放入$ body(例如:“$ body ='test';”) - 并查看是否存储 - 如果没有,那么这就是你的问题。
  • 删除文件(删除任何权限问题)。
  • 仔细检查支付网关发送到的网址是否正确。