Sending HTTPS POST Message with XML Content


HTTPS POST XML

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

2.1) Go to file php.ini,  uncomment these two lines to use CURL and OPENSSL
extension=php_curl.dll
extension=php_openssl.dll

2.2) Make sure that libeay32.dll and ssleay32.dll must be present in the PATH environment variable.

If we successfully enable CURL,  when we check with phpinfo() funciton, we will get

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://th.php.net/curl

http://www.basecamphq.com/forum/viewtopic.php?pid=8434

 

 

คำสำคัญ (Tags): #uncategorized
หมายเลขบันทึก: 28166เขียนเมื่อ 12 พฤษภาคม 2006 15:57 น. ()แก้ไขเมื่อ 6 กันยายน 2013 17:22 น. ()สัญญาอนุญาต: จำนวนที่อ่านจำนวนที่อ่าน:


ความเห็น (0)

ไม่มีความเห็น

พบปัญหาการใช้งานกรุณาแจ้ง LINE ID @gotoknow
ClassStart
ระบบจัดการการเรียนการสอนผ่านอินเทอร์เน็ต
ทั้งเว็บทั้งแอปใช้งานฟรี
ClassStart Books
โครงการหนังสือจากคลาสสตาร์ท