我目前有一个程序可以在服务器上运行测试,它会将结果发送到test.php文件。我正在尝试将我的POST数据重定向到reports.php页面,这些数据是JSON格式的,我想在reports.php中很好地(最终)显示页面上的数据。数据进展缓慢,当我将test.php
中的网址更改为requestb.in中指定的网址时,我能够在https://requestb.in/中看到数据。我知道在test.php
我从reports.php
卷起的所有内容它只会回显到test.php
目前,当我打开report.php时,我会在发送数据后得到一个空白页面。我需要做一些事情,就像requestb.in处理传入数据并显示它一样,我该怎么做?
test.php
#!/usr/bin/php
<?php
// turn on error reporting
error_reporting(E_ALL);
ini_set('display_errors', 'On');
//URL to POST JSON data to
$url = "http://my/dir/to/reports.php"; //if changed to requestb.in URL then i can see correct data
$post_data = array(
'id' => $argv[1],
'version' => $argv[2],
'server' => $argv[3],
'status' => $argv[4],
'test' => $argv[5],
'time' => $argv[6],
'body' => $argv[7],
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$result = curl_exec($ch);
if (curl_error($ch)) {
echo 'Curl error: ' . curl_error($ch);
} else {
echo "success: \n\n";
print_r($result);
}
curl_close($ch);
?>
reports.php
<?php //reports.php
//This php file is to receive the POST data coming from php files.
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
print_r($_POST);
}
?>