Currently, there are many sites that make XML available and we need to send HTTPS POST message request properly in order to get the result back.
To do that by using PHP on Windows environment, we need to ensure these following requirements.
1) We should check the XML content whether it is
well-formed and valid before we send the message. This can be
done by using various tools, such as Eclipse with XML plugin and
NetBeans 5.0
2) For the URL that is HTTP over SSL, we need to use CURL
library. That is we need to enable CURL support which can be
done as follows
3) Use CURL functions in the PHP program that we connect
to GHRS
$URL=" https://www.ghrshotels.com/adm/interface_test/xml/ota/";
$data = "
http://www.opentravel.org/OTA/2003/05"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.opentravel.org/OTA/2003/05
http://www.opentravel.org/2003A/OTA_PingRQ.xsd"
Target="Test" Version="1.000" SequenceNmbr="1">Test Klub";
// Init curl
$ch = curl_init();
// Set Curl Option: Set url for the post
curl_setopt($ch, CURLOPT_URL,$URL);
// Set Curl Option: Enable http post
curl_setopt($ch, CURLOPT_POST, 1);
// Set Curl Option: Set post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Set Curl Option: Enable http header setting
curl_setopt($ch, CURLOPT_HEADER, true);
// Set Curl Option: Specify that http content is XML through HTTP
header
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:
application/xml', 'Content-Type: application/xml'));
// Set Curl Option: Collect result from script
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set Curl Option: Set timeout to 15 seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
// tell cURL to graciously accept an SSL certificate if
presented
if(ereg("^(https)",$URL))
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
// Execute and send HTTP POST message
$result = curl_exec ($ch);
// Check whether there is error
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
echo $result;
?>
If we successfully send the request, we will get the response as shown below:
Resources:
http://www.basecamphq.com/forum/viewtopic.php?pid=8434
ไม่มีความเห็น