0

我有一个发送者脚本和一个接收者脚本。发送者发送一个 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 =

那我做错了什么?我应该在我的发件人/收件人上添加什么才能得到回复?

4

1 回答 1

0

替换以下行:

$ch_result = curl_exec($ch);
echo "Result = " . $ch_result;

使用以下几行,看看它是否有效:

$ch_result = curl_exec($ch);
$ch_header = curl_getinfo($ch);
echo "Status : " . $ch_header['http_code'] . "<br />";
echo "Result = " . $ch_result;

curl_getinfo返回有关请求的基本信息和变量http_code返回响应代码 200,404 等。然后您可以检查代码并根据您的要求对其进行解析。

希望能帮助到你。

于 2013-01-18T10:17:06.037 回答