【发布时间】:2018-09-09 15:10:48
【问题描述】:
我的 curl 有问题,我尝试使用 CURL 获取内容但只返回 null,我不知道我错过了什么,请告诉我,这是我的代码:
$url = "https://shopee.co.id/api/v1/search_items/?by=pop&order=desc&keyword=yi 067&newest=0&limit=50&page_type=shop&match_id=16775174";
$html = file_get_contents_curl($url);
var_dump($html);
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_ENCODING, 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST , "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'));
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
【问题讨论】:
-
您缺少一些错误报告。我猜是 SSL。
-
你应该看到这个答案:a link
-
我使用了这个确切的代码并得到了一些 HTML,但是那个 html 定义了一个包含正文内容的简单文档。 @CSM 你确定它返回的是 NULL 而不是 FALSE 或空字符串?