Hi All
I am passing XML data to a URL using cURL:
[FONT="Courier New"]
$useurl = "https://www.mydomain.com/xmlupdate.php";
$sendXML = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<ordershipping>
<shippingheader>
<shippingtransid>23423123</shippingtransid>
<ordernumber>99</ordernumber>
<shippingdate>2008-09-23</shippingdate>
<carriername>FedEx</carriername>
<trackingid>ABCDEFGHIJKLMNO</trackingid>
</shippingheader>
<shippingdetails>
<batchnumber>batch1</batchnumber>
<quantity>2</quantity>
</shippingdetails>
</ordershipping>";
$curl = curl_init($useurl);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml"));
curl_setopt($curl, CURL_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $sendXML); // post the xml
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // set timeout in seconds
$xmlResponse = curl_exec ($curl);
curl_close ($curl);
[/FONT]
On the server is xmlupdate.php:
[FONT="Courier New"]
<?php
$xmldata = $GLOBALS['HTTP_RAW_POST_DATA'];
$xml = @simplexml_load_string($xmldata);
print_r($xml);
?>
[/FONT]
When I try this local on my workstation the following is displayed:
[FONT="Courier New"]
SimpleXMLElement Object ( [shippingheader] => SimpleXMLElement Object ( [shippingtransid] => 23423123 [ordernumber] => 99 [shippingdate] => 2008-09-23 [carriername] => FedEx [trackingid] => ABCDEFGHIJKLMNO ) [shippingdetails] => SimpleXMLElement Object ( [batchnumber] => batch1 [quantity] => 2 ) )
[/FONT]
However when I try this on the server no SimpleXMLElement is displayed. It is as if the XML data is not being parsed at all.
If the xmlupdate.php file contains the following PHP code:
[FONT="Courier New"]
<?php
$xmldata = $GLOBALS['HTTP_RAW_POST_DATA'];
echo $xmldata;
?>
[/SIZE][/FONT]
The following is displayed:
[FONT="Courier New"]
23423123 99 2008-09-23 FedEx ABCDEFGHIJKLMNO batch1 2
[/FONT]
This would suggest to me the XML data is being passed correctly by cURL.
My question is why can I not display the SimpleXMLElement when I use the server?
Can anyone tell me please. I am pretty desperate.
Thanks in advance.
BB