我们目前正在使用Ultracart将xml回发到服务器上的url。我要做的是接收xml,然后右转并将其发布到另一个页面。(我们在为一个正在进行的项目向多个来源发送回邮时遇到了问题。)以下是我一直在玩的游戏:
$xml = file_get_contents('php://input');
$url = 'https://destinationlink';
$post_data = array(
"xml" => $xml,
);
$stream_options = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded'r'n",
'content' => http_build_query($post_data),
),
);
$context = stream_context_create($stream_options);
$response = file_get_contents($url, null, $context);
我知道我错过了一些重要的东西。。。我想我看得太久了,我看不出问题。。。可能是愚蠢的简单。
原来CURL就是答案。
//URL where to send the data via POST
$URL1 = 'http://destinationlink';
//the actual data
$xml_data1 = file_get_contents('php://input');
$ch1 = curl_init($URL1);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch1, CURLOPT_POST, 1);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch1, CURLOPT_POSTFIELDS, "$xml_data1");
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
$output1 = curl_exec($ch1);
curl_close($ch1);
这很有魅力。
我可以接收XML回发(php://input),使用这个curl代码根据目标URL制作不同的块,并将信息逐个发送到我需要的所有独立连接。