Reputation: 6918
I am using curl to get data from API, that is returning me different guid every time. i am using the below code:
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'https://aapiconvention2016.sched.org/api/auth/login?api_key=f8bf836da29b0831ff1f03fce3c64462&username=*****&password=****');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'API HIT');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
echo $query
before it was returning 500 internal error. i fixed it by using above code. but now i am not getting any error or output.
i am not getting why it is not working, please help me
thanks in advance.
Upvotes: 1
Views: 169
Reputation: 740
Please set ssl verification false by add this line
curl_setopt($curl_handle,CURLOPT_SSL_VERIFYPEER, false);
and then your code will be like this :
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'https://aapiconvention2016.sched.org/api/auth/login?api_key=f8bf836da29b0831ff1f03fce3c64462&username=*****&password=****');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'API HIT');
curl_setopt($curl_handle,CURLOPT_SSL_VERIFYPEER, false);
$query = curl_exec($curl_handle);
curl_close($curl_handle);
echo $query;
Upvotes: 1
Reputation: 297
You can get the last error code using curl_errno
and the last error string using curl_error
. These gave me a timeout error.
Therefore you can get an answer by increasing the default curl timeout to e.g. 10 seconds and the overall function timeout to e.g. 15 seconds:
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 15);
Upvotes: 1