Ever try to post XML over HTTPS using php ?
Well it can get almost complicated if you don’t have the right materials.
In this article I will show you how to do it using PHP’s cURL functions.
Requirements:
1- libcurl package ( In PHP 4.2.3, you will need libcurl version 7.9.0 or higher. From PHP 4.3.0, you will need a libcurl version that’s 7.9.8 or higher. PHP 5.0.0 requires a libcurl version 7.10.5 or greater )
Installation
1- Go to http://curl.haxx.se/download.html and download the corresponding libcurl package.
2- For windows users you will have to enable the ‘;extension=php_curl.dll’ in the php.ini file. (libeay32.dll and ssleay32.dll must be present in your PATH.)
For linux/unix users you will have to compile build and then install the package using these 3 steps:
./configure
make
make installNote: You will have to be root in order to do the last step (more info can be found here)
3- Restart apache
Now that your libcurl package is installed you can use the curl library functions.
The function that we will use to POST those nasty XMLs is something like this:
$Url : the url at which i am posting the XML
$strRequest: The XML that i am posting
function httpsPost($Url, $strRequest) { // Initialisation $ch=curl_init(); // Set parameters curl_setopt($ch, CURLOPT_URL, $Url); // Return a variable instead of posting it directly curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Active the POST method curl_setopt($ch, CURLOPT_POST, 1) ; // Request curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // execute the connexion $result = curl_exec($ch); // Close it curl_close($ch); return $result; }
#usage
$url = 'https://joeabiraad.com/'; $strRequest = utf8_encode('<request RequestType="xxx" RequestUserName="xxx" RequestPassword="xxx" />'); $Response = httpsPost($url, $strRequest);
As you can see i tried to comment it as much as i can…
Here I am returning the result instead of posting it directly, you can change this by removing this command ‘ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);’
Enjoy
and if you have any questions… do ask
Popularity: 12% [?]

Thanks for the example. Copied as is
Thanks for the example.
I tried running this script from my local machine. It returned a value of 1.
How can i receive xml data from the server through HTTPS.
Great. I am looking for this solution.
Is this possible with only javascript with an old and unsecure borwser like i.e.?