我有这段代码,通过 cURL 将 XML 文件中的数据发送到新闻办公室。现在我希望得到媒体的反馈,表明我的订单已确认或完成。我也希望将其包含在 XML 文件中。我知道如何通过curl发送文件,现在我想知道如何接收它们,以便我可以读出数据。欢迎任何建议。
这就是我发送 XML 的方式:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $incomm_prod_server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, str_replace('{voucher_code}', $voucher_code, $xml_data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
这就是我在另一边所做的获取 XML 的操作:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result_xml = simplexml_load_string(curl_exec($ch));
但我得到 bool(false) 作为结果返回,所以没有发送 xml?
编辑:我可以这样访问数据:
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
$postText = file_get_contents('php://input');
}
die(var_dump($postText));
我最后一次编辑,也许对其他人有帮助,我现在以这种方式访问我的 xml:
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
$postText = file_get_contents('php://input');
}
$xml = new SimpleXMLElement($postText);
$packing_number = $xml->xpath('/feedback/packing_number');
$packing_status = $xml->xpath('/feedback/packing_status');
这会给你一个数组,你可以像下面这样访问它:
$包装编号[0]
或者只是循环遍历它。