note 103604 modified in function.fopen by danbrown

From: Date: Fri, 22 Apr 2011 12:09:58 +0000
Subject: note 103604 modified in function.fopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179077@lists.php.net to get a copy of this message
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; } ?> --was-- Function for doing POST requests using fopen 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; } http://php.net/manual/en/function.fopen.php

« previous php.notes (#179077) next »