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

时间:2015-09-19 06:16:40

标签: php json curl

我有一个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>';

1 个答案:

答案 0 :(得分:1)

您的代码看起来是正确的。问题是网址。我猜它要求验证以获取json数据。

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