linux - 无法在 Linux 服务器中打开流 : HTTP request failed! HTTP/1.1 500 内部服务器错误

标签 linux file-get-contents internal-server-error

我想从这里获取提要http://laimoon.com/feed/jobs?search=female,arts&locations=2 如果我直接在浏览器中浏览此页面,它会显示提要,如果我在 Windows 上的本地主机中使用此代码

$xml=simplexml_load_file("http://laimoon.com/feed/jobs?search=female,arts&locations=2"); 
print_r($file_contents); 
                  OR
$file_contents = file_get_contents('http://laimoon.com/feed/jobs?search=female,arts&locations=2')
print_r($xml);

Both works fine 

但是如果我在我的 linux live 服务器中使用这段代码,那么它会显示这个错误 file_get_contents()

 Warning: file_get_contents(http://laimoon.com/feed/jobs?search=female,arts&locations=2): failed to open stream :HTTP request failed! HTTP/1.1 500 Internal Server Error

simplexml_load_file() 的错误

Warning: simplexml_load_file(http://laimoon.com/feed/jobs?search=female,arts&locations=2): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

提前致谢:)

最佳答案

最后我得到了我预期的结果,我只是在 curl 链接中启用 curl_setopt($ch, CURLOPT_POST, true); 并且我得到了我的结果但是还有一个问题现在已经解决了... 在此之后,我使用 simplexml_load_string($ret);

加载该 xml 数据

但它没有读取 CDATA 然后我只添加了两个参数

 simplexml_load_string($ret,'SimpleXMLElement', LIBXML_NOCDATA);

然后我得到了我预期的结果...... 这是我的完整代码

$header = array('Content-Type:application/xml', 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1');
$ch = curl_init();
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate,sdch');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201");
curl_setopt($ch, CURLOPT_URL, "http://laimoon.com/feed/jobs?search=female,arts&locations=2");
curl_setopt($ch, CURLOPT_POSTFIELDS, $loginFields);
$ret = curl_exec($ch);
curl_close($ch);

$xml = simplexml_load_string($ret,'SimpleXMLElement', LIBXML_NOCDATA);

$chl = $xml->children()->children();
$items = $chl->item;
foreach($items as $item){
  echo (string)$item->title."</br>";
  echo (string)$item->description."</br>";
  echo (string)$item->pubDate."</br>";
  echo (string)$item->link."</br>";

}

谢谢@Mike W

关于linux - 无法在 Linux 服务器中打开流 : HTTP request failed! HTTP/1.1 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21449886/

相关文章:

python - rc.local shell 脚本启动时缺少文件

linux - 从 vi/vim 中运行命令

PHP:在类构造函数中使用 file_get_contents() 是一种不好的做法吗?

php - 回答回调查询

c - C : fork or fork + exec 中多处理应用程序的体系结构

c - 从不断更新的文件中读取

phpunit - WebTestCase Phpunit 发送原始数据不起作用

java - 在 TOMCAT 上部署 WAR 文件仅对使用 APPLICATION_JSON 的 REST API 抛出错误

python - Django 内部服务器 500 错误 AWS Elastic-Beanstalk 问题

ASP.NET:HTTP 错误 500.19 – 内部服务器错误 0x8007000d