Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl_exec return null in php

Tags:

php

curl

I have a problem to get the data using curl operation. Here i hide the token, If i use the url only in my browser then it returns the data but here its null.

<?php 
$token = "TOKEN"; //the actual token hidden
$url = "https://crm.zoho.com/crm/private/xml/Leads/getRecords?authtoken=".$token."&scope=crmapi";
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);

$result = curl_exec($ch);
curl_close($ch);
echo $result; //does not return anything
?>

Where i do mistake please help me.

like image 434
MuteX Avatar asked Mar 23 '15 05:03

MuteX


1 Answers

This is how you can try with CURLOPT_RETURNTRANSFER which is used to return the output and curl_errno() to track the errors :

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://example.com/my_url.php" ); 
curl_setopt($ch, CURLOPT_POST, 1 ); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$postResult = curl_exec($ch); 

if (curl_errno($ch)) { 
   print curl_error($ch); 
} 
curl_close($ch); 

Helpful Links: curl_errno(), curl_error()

like image 118
jogesh_pi Avatar answered Nov 03 '22 01:11

jogesh_pi