使镶边显示 rss 源 (2)


Make chrome display an rss feed (2)

这个问题是这个问题的后续问题:让谷歌浏览器查看RSS提要

我从此页面复制了源代码(希望这对网站所有者来说没问题):
http://www.petefreitag.com/rss/。
我转义了所有引号,并用它制作了一个php文件。该文件如下所示:

<?php
header('Content-Type: application/rss+xml');
echo "<?xml version='"1.0'" ?>
<?xml-stylesheet type='"text/css'" href='"http://www.petefreitag.com/rss/simple_style.css'" ?>
<rss version='"2.0'">
    <channel>
        <title>Pete Freitag's Homepage</title>
        <link>http://www.petefreitag.com/</link>
        <description>Covering ColdFusion, Java, Web Development, and other topics</description>
        <language>en-us</language>
        <lastBuildDate>Fri, 23 Mar 2012 18:57:00 GMT</lastBuildDate>
        <ttl>45</ttl>
        <item>
REST OF THE SOURCE CODE
</rss>
";
?>

在这里你可以看到结果:http://web.student.tuwien.ac.at/~e0250890/rsstest/test.php

但是,在 http://www.petefreitag.com/rss/chrome将页面视为rss feed,在我的示例中,它仅显示源代码。

有什么区别,如何强制 chrome 以 rss 提要的形式查看页面?

尝试将标题更改为application/xml

这通过更改标题对我有用:

<?php 
header('Content-Type: application/xml');
echo file_get_contents('http://web.student.tuwien.ac.at/~e0250890/rsstest/test.php');
?>

Mozilla 接受各种标头

text/xmlapplication/xmlapplication/rss+xmlapplication/atom+xml

但似乎铬只接受text/xmlapplication/xml

不是100%确定为什么,也许你应该用谷歌;p

添加文档类型。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">