Sunday, December 22, 2013

Using Curl With PHP

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => 'https://int.mylinkables.com/consumerapi/consumer',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

//Using Header with Curl
curl_setopt($ch, CURLOPT_HEADER, true);
$headr = array();
$accesstoken="0_1c178f77-7d30-4a49-a1df-e1f9cf021d0b";
$headr[] = 'Accept: application/json';
$headr[] = 'api: 1.0.0';
$headr[] = 'Authorization: Bearer '.$accesstoken;
curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
//curl_setopt($ch, CURLOPT_POST,true);
$file_contents  = curl_exec($ch);

if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}

// Close handle
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_close($ch);

No comments:

Post a Comment