我有一个发送者脚本和一个接收者脚本。发送者发送一个 xml 文件,而接收者获取它并将其存储在数据库中。
发件人看起来像这样:
$xml = file_get_contents("data.xml");
// We send XML via CURL using POST with a http header of text/xml.
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://localhost/iPM/receiver.php");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, 'http://localhost/iPM/receiver.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
echo "Result = ".$ch_result;
curl_close($ch);
和接收器:
$xml = file_get_contents('php://input');
parsing the xml - storing to database
etc etc etc etc etc etc etc etc etc
当我运行发送者脚本时,我需要从接收者那里得到一切正常并且收到 xml 文件的响应。我相信我会在这行代码中看到这一点,在我的代码中: echo "Result = ".$ch_result;
但我看到打印的唯一内容是Result =
。
那我做错了什么?我应该在我的发件人/收件人上添加什么才能得到回复?