php - HTTP / 1.1 500 file_get_contents上的内部服务器错误

时间:2015-02-05 12:39:51

标签: php

因为标题说我得到了 - file_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

URL http://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,它表明字符串每次都是空的。 我也谷歌搜索并尝试了其他解决方案,但都没有。

编辑: 对于某些人来说链接即使在浏览器上也会出错,但对我来说工作正常,所以这里是链接的图片供参考 http://i.stack.imgur.com/VM09P.png

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

1 个答案:

答案 0 :(得分:0)

完全忘记发布此解决方案。 问题是,该页面需要以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