文件_get_contents上的HTTP/1.1 500内部服务器错误


HTTP/1.1 500 Internal Server Error on file_get_contents

正如标题所说,我得到了文件_get_contents上的HTTP/1.1 500内部服务器错误这是错误日志-

 ! ) Warning: file_get_contents(http://thepilotslife.com/assets/chat-output.php): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:'wamp'www'test'index.php on line 3

URLhttp://thepilotslife.com/assets/chat-output.php在borwser中打开得很好,试着打开自己,试着每5秒在浏览器中重新加载一次URL,你不会发现每次输出都是不同的,所以我基本上需要从那个URL中获取数据,然后对它执行某些任务。这是php文件内容-

<?php
$baseurl = "http://thepilotslife.com/assets/chat-output.php";
$response = file_get_contents($baseurl);
echo $response;
?>

我也尝试以以下方式使用CURL

<?
$url = "http://thepilotslife.com/assets/chat-output.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
?>

上面的CURL代码没有给出任何错误,但每次只给我一个空白页。。我在CURL代码中也使用了var_dump,它显示每次字符串都是空的。我还在谷歌上搜索并尝试了其他解决方案,但都不起作用。

编辑:对于一些人来说,即使在浏览器上,链接也会出错,但对我来说效果很好,所以这里是链接的图片供参考https://i.stack.imgur.com/VM09P.png

还请注意,file_get_contents和CURL与其他链接完美配合

完全忘记发布这个问题的解决方案。问题是,该页面需要一个以cookie形式存储的php会话id才能工作。无论如何,这就是我解决问题的方法:

$ch = curl_init();//initialize the curl
curl_setopt($ch, CURLOPT_URL, 'https://thepilotslife.com/chat');//this page sets cookie
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//to overcome SSL verification
curl_exec($ch);//execute the curl to get and set cookies
curl_setopt($ch, CURLOPT_URL, 'https://thepilotslife.com/assets/chat-output.php');//now set the url to page which we needed the output from
echo curl_exec($ch);//echo the result