404 未找到 PHP
我尝试使用 Curl 或 file_get_contents 访问远程数据,但它们都返回 404 Not found。浏览器和不同服务器上的相同链接有效。也许 php 配置中禁用了某些内容?
这是与 Curl 和文件获取内容相同的函数:
public function getNowPlaying() {
$source = "http://v12.radionsm.lv/lv/stats";//$this->url . "/lv/stats";
$ch = curl_init($source);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (curl_exec($ch) === FALSE) {
die("Curl error: " . curl_error($ch));
}
$data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
$data = array(
'status' => (string) $xml->status,
'onAir' => (string) $xml->dj_name,
'artist' => (string) $xml->artist_name,
'title' => (string) $xml->song_name,
'albumArt' => (string) $this->medium($xml->song_pic)
);
return $data;
}
public function getNowPlaying() {
$source = "http://v12.radionsm.lv/lv/stats";
echo file_get_contents($source);
}
谢谢。
I'm trying to access remote data with Curl or file_get_contents, but they both return 404 Not found. The same link in browser and on different server works. Maybe something is disabled in php config?
Here is the same function with Curl and file get contents:
public function getNowPlaying() {
$source = "http://v12.radionsm.lv/lv/stats";//$this->url . "/lv/stats";
$ch = curl_init($source);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (curl_exec($ch) === FALSE) {
die("Curl error: " . curl_error($ch));
}
$data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
$data = array(
'status' => (string) $xml->status,
'onAir' => (string) $xml->dj_name,
'artist' => (string) $xml->artist_name,
'title' => (string) $xml->song_name,
'albumArt' => (string) $this->medium($xml->song_pic)
);
return $data;
}
public function getNowPlaying() {
$source = "http://v12.radionsm.lv/lv/stats";
echo file_get_contents($source);
}
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是对汽车报废的某种保护。因此,您需要重复浏览器行为才能阅读该页面。
尝试使用有效的主页网址设置 CURLOPT_REFERER。您需要在curl 请求中发送每个人标头,该标头由浏览器发送。
I think this is some kind of protection from auto scrapping. So you need to repeat browser behaviour to get read that page.
Try to set up CURLOPT_REFERER with valid homepage url. You need to send everyone header in your curl request, which is sent by browser.