Apr 4 2008
PHP post without curl
- 2 Comment
You can simulate the post method using php without the help of curl library.
download full source code:
![]()
See the code below:
function do_post_request($url, $data, $optional_headers = null) {
$params = array('http' =>; 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;
}
?>
Download the full source code from post_without_curl.zip
2 Comments on this post
Trackbacks
-
Binny V A said:
An easier way to do this - load() function. With and without curl
April 4th, 2008 at 11:44 am -
Sajith M.R said:
Both are almost same , i think
April 4th, 2008 at 12:04 pm




