note 103604 deleted from function.fopen by salathe
| From: | salathe@php.net | Date: | Wed, 11 May 2011 08:48:32 +0000 |
| Subject: | note 103604 deleted from function.fopen by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179600@lists.php.net to get a copy of this message | ||
Note Submitter: jakub dot kulak at gmail dot com
Reason: in docs
----
Function for doing POST requests using fopen
<?php
function postRequest($url, $data, $headers = null) {
$params = array(
'http' => array(
'method' => 'POST',
'content' => $data
));
if ($headers !== null) {
$params['http']['header'] = $headers;
}
$context = stream_context_create($params);
$handle = @fopen($url, 'rb', false, $ctx);
if (!$handle) {
// throw exception
}
$response = @stream_get_contents($handle);
if ($response === false) {
// throw exception
}
return $response;
}
?>