Powered by Blogger.

what is the alternate of curl in php



Http method get example
------------------------------------
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: ".$_SERVER['HTTP_USER_AGENT']
    )
);
$context = stream_context_create($opts);
file_get_contents( $url, false, $context);


Http method post example
---------------------------------
$data = array ('foo' => 'bar', 'bar' => 'baz');
$data = http_build_query($data);
$opts = array (
        'http' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
                . "Content-Length: " . strlen($data) . "\r\n",
            'content' => $data
            )
        );
$context = stream_context_create($opts);
file_get_contents( $url, false, $context);

No comments