Something to keep in mind when creating SSL streams (using https://):
<?php
$context = context_create_stream($context_options)
$fp = fopen('https://url', 'r', false, $context);
?>
One would think - the proper way to create a stream options array, would be as follows:
<?php
$context_options = array (
'https' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);
?>
THAT IS THE WRONG WAY!!!
Take notice to the 3rd line: 'https' => array (
The CORRECT way, is as follows:
<?php
$context_options = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);
?>
Notice, the NEW 3rd line: 'http' => array (
Now - keep this in mind - I spent several hours trying to trouble shoot my issue, when I finally stumbled upon this non-documented issue.
The complete code to post to a secure page is as follows:
<?php
$data = array ('foo' => 'bar', 'bar' => 'baz');
$data = http_build_query($data);
$context_options = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($data) . "\r\n",
'content' => $data
)
);
$context = context_create_stream($context_options)
$fp = fopen('https://url', 'r', false, $context);
?>