Thanks for answering …
After some search and test, this is a working code using cURL for XML POST to a webservice :
As somebody needed
Nac
define('XML_PAYLOAD', 'xmlstring=<request><UserName>USER</UserName><Password>PASS</Password><HotelId>ID</HotelId></request>');
define('XML_POST_URL', 'https://...url..../RequestReservations');
/**
* Initialize handle and set options
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type text/xml'));
$start = array_sum(explode(' ', microtime()));
$result = curl_exec($ch);
$stop = array_sum(explode(' ', microtime()));
$totalTime = $stop - $start;
/**
* Check for errors
*/
if ( curl_errno($ch) ) {
$result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
} else {
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
switch($returnCode){
case 404:
$result = 'ERROR -> 404 Not Found';
break;
default:
break;
}
}
/**
* Close the handle
*/
curl_close($ch);
echo 'Total time for request: ’ . $totalTime . "
";
$xml = new SimpleXMLElement($result);
RecurseXML($xml,"");
function RecurseXML($xml, $parent)
$child_count = 0;
foreach($xml as $key=>$value)
{
$child_count++;
if(RecurseXML($value,$parent.".".$key) == 0) // no childern
{
print($parent . “.” . (string)$key . " = " . (string)$value . "<BR>
");
}
foreach($value->attributes() as $a => $b) {
print($parent . "." . (string)$key . "." . (string)$a. "= ". (string)$b . "<BR>
");
}
}
return $child_count;