I am trying to call a API from curl, and this works fine in postman.when running in php this never goes passed the curl_exec call.have tried many options and read many other posts, but to no avail.Any advice appreciated
$url = "http://stats.nba.com/stats/scoreboardV2?Season=2017-18&LeagueID=00&GameDate=10/17/2017&dayoffset=0";
//$url= urlencode($url);
$curl = curl_init($url); // we init curl by passing the url
print("a");
#curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
#curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
#curl_setopt($curl,CURLOPT_POST,false); // to send a POST request
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
#curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
#curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
#curl_setopt($curl, CURLOPT_TIMEOUT, 30);
#curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect: 100-continue'));
print("b");
#curl_setopt($curl,CURLOPT_POSTFIELDS,$access_token_parameters); // indicate the data to send
#curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
print("c");
#curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // to stop cURL from verifying the peer's certificate.
print("d");
$result = curl_exec($curl) or die("cURL Error" . curl_error($curl)); // to perform the curl session
print("e");
curl_close($curl);
From postman you can get the generated code also. This is what I got with your given URI, so lets try this and let me know whether it works or not?
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://stats.nba.com/stats/scoreboardV2?Season=2017-18&LeagueID=00&GameDate=10/17/2017&dayoffset=0",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET"
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}