【发布时间】:2016-12-17 22:00:27
【问题描述】:
我正在尝试从以下网址获取文本。 http://stp.stheadline.com/data/indexNewsMarquee.json
我尝试了几种方法,但都没有奏效。我现在真的很绝望,请帮助我并提前感谢。
附:我已经在我的 ini.php 中启用了 allow_url_fopen。 附言我正在使用 XAMPP v3.3.2 和 PHP v5.6.23
以下是我尝试过(但失败)的代码
卷曲
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
结果:空字符串
file_get_contents
echo file_get_contents($url, true);
结果:打开流失败:HTTP 请求失败!
读取文件
echo readfile($url)
结果:输出地址本身
【问题讨论】:
-
查看以下链接。不需要 curl 功能。 stackoverflow.com/questions/19758954/…
标签: php http url curl file-get-contents