使用CURL返回NULL从Json url获取数据


Getting data from Json url using CURL Returning NULL

我有一个JSON链接,我想从它获得数据,但它返回NULL。

代码:

$url = 'https://cheddargetter.com/json/customers/search/orderBy/id/orderByDirection/asc/perPage/100/';
//  Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
// Will dump a beauty json :3
//var_dump(json_decode($result, true));                                                                                              
echo '<pre>abc'. print_r($result) . '</pre>';

您的代码看起来正确。问题是url。我猜它需要认证来获取json数据。

https://cheddargetter.com/?fwd=%2Fjson%2Fcustomers%2Fsearch%2ForderBy%2Fid%2ForderByDirection%2Fasc%2FperPage%2F100%2F#login