I am trying to get used to using cURL, and have hit a wall. Currently I have two php scripts, a "sender" hosted on one site and a "receiver" hosted under a different domain on a totally different site. I want the sender to read in an xml file saved in a folder, and post it to the receiver. Then when I load the receiver page, I want to see the contents of the xml displayed on screen.
Here is my code so far.
SENDER.
//Load the xml file, into an object called $message.
if(file_exists('../XML/example.xml')) {
$message = simplexml_load_file('../XML/example.xml');
}
else
{
exit ('Could not load the xml file from the specified path location');
}
//POST the data using cURL to the receiving page.
$url = "http://dev.somewhere_else.com/receiver.php"; //destination
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
// The output gets generated and looks like an array
eg:
array(4) { ["@attributes"]=> string(5) "Array" ["header_section"]=> string(23) " " ["application_section"]=> string(18) " " ["name"]=> string(7) "example" }
So far so good? In theory this means the response via cURL is the expected data. However when I go to the other site and load the receiving page, instead of seeing something similar I get.....
array(0) { }
result =
RECEIVER.
// Display the contents of the super global..
var_dump($_POST);
This displays "array(0) {}" here on this page. I suspect because the data is xml, and so $_POST isn't populated. Puzzling though, as the response the sender gets display's correctly. To fix this I added..
$dataFromPost = file_get_contents('php://input');
echo"<br><br>result =";
echo $dataFromPost;
So these last three lines should read the incoming stream from my "sender" and put it in the $dataFromPost variable. It should then display it on the screen, but all i get is blank...
I've read countless examples and followed many different guides, but can't get it to work the way I expect it to. Can anyone please put me out of my misery?