我需要检索一个Web内容.我通常使用wget,但这次它给了我一个"内部服务器错误".我也尝试使用file_get_contents(),当我在我的Mac上安装MAMP时它可以工作,但是当我在我们的服务器上运行它时,它没有做任何事情并且没有打印错误消息.有没有其他方法可以做到这一点?以下是我使用的代码.
<?php
echo "Retrieving Traffic Updates";
$source = file_get_contents('http://www4.honolulu.gov/hpdtraffic/MainPrograms/frmMain.asp?sSearch=All+Incidents&sSort=I_tTimeCreate');
echo $source;
?>
Run Code Online (Sandbox Code Playgroud)
提前致谢!!
我不知道如何回复你们所有人,所以我在这里添加了它.CURL完美地工作.非常感谢你们.我只是要问,为什么即使在php.ini中启用了file_get_contents()也无法工作?
你可以使用cURL:
<?php
echo "Retrieving Traffic Updates";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www4.honolulu.gov/hpdtraffic/MainPrograms/frmMain.asp?sSearch=All+Incidents&sSort=I_tTimeCreate");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$source = curl_exec($ch);
curl_close($ch);
echo $source
?>
Run Code Online (Sandbox Code Playgroud)