任何关于为什么以下不起作用的想法.
$request_url = "someurl?myId=$id"; //returns feed like above
$json = file_get_contents($request_url, true); //getting the file content
$decode = json_decode($json, true);
var_dump($json);
当我将request_url粘贴到浏览器中时,我得到了json数据但是如果我在php中尝试,则var_dump只是bool(false);有任何想法吗??
更新并修复
好的家伙感谢所有的帮助.你帮我跟踪了这个.事实证明,php.ini配置为禁止打开网址,因此file_get_contents不起作用.我找到了各种网站上提到的以下方便功能,并使用它进行排序.这是我使用的方法,以防它帮助其他人.
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}