HTTP POST without cURL library - PHP
Found this interesting function that can handle a HTTP POST without using redirects or any special hacks. This is extremely useful for sending data over a secure HTTPS POST or to another web site. cURL is probably the better choice here, but if you don’t have the library avaliable, (like many developers because of strict hosting solutions), this function might be your best bet.
Anyway on to the code. I found this awesome code snippet at: http://netevil.org/node.php?nid=937
I encourage you to check out some other parts of this guys site, pretty good stuff.
array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
?>
well…I found many people referencing that particular function…but no one seem to provide any examples of using it.
I’ve try to use it…but no luck for me so far
any chance for an example please.
thanks