即时通讯目前与需要我们使用POST请求发送我们收集的信息在XML中的服务器API工作。

没什么大事有,但其没有工作,所以我想输出的XML发送到一个txt文件,所以我可以看看什么实际发送!

除了张贴到API IM张贴到一个文件名为目标,但其输出其记录的XML似乎是真的错了。这是我的目标脚本,注意张贴脚本职位3项,所以写入的文件应该在其他以后让每个岗位要求一个细节。

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

// get the request data...
$payload = '';
$fp = fopen('php://input','r');
$output_file = fopen('output.txt', 'w');
while (!feof($fp)) {
    $payload .= fgets($fp);
    fwrite($output_file, $payload);
}

fclose($fp);
fclose($output_file);
?> 

我也试过以下,但这个刚刚录制的最后一个职位的要求所以只有1个集项目被记录在txt文件,而不是所有3

output_file = fopen('output.txt', 'w');
while (!feof($fp)) {
    $payload .= fgets($fp);
}
fwrite($output_file, $payload);
fclose($fp);
fclose($output_file);

我知道我在想念的东西真的很明显,但我一直都在寻找这一切早上!

有帮助吗?

解决方案

更改

$output_file = fopen('output.txt', 'w');

$output_file = fopen('output.txt', 'a');

此外,变化

$payload .= fgets($fp);

$payload = fgets($fp);

其他提示

您应该使用卷曲,而不是获取内容,然后通过fwrite的

变化

  $payload .= fgets($fp);

 $payload = fgets($fp);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top