问题
This question is a follow-up on this one: get google chrome to view an rss feed
I copied the source code from this page (hope this is ok for the site-owner):
http://www.petefreitag.com/rss/.
I escaped all quotes and made a php file out of it. The file looks like this:
<?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>
";
?>
Here you can see the result: http://web.student.tuwien.ac.at/~e0250890/rsstest/test.php
However, on http://www.petefreitag.com/rss/ chrome views the page as rss feed, in my example it shows just the source code.
What is the difference and how can I force chrome to view the page as rss feed?
回答1:
Try changing the header to application/xml
This worked for me by changing the header:
<?php
header('Content-Type: application/xml');
echo file_get_contents('http://web.student.tuwien.ac.at/~e0250890/rsstest/test.php');
?>
Mozilla accepts a whole range of headers
text/xml
,application/xml
,application/rss+xml
,application/atom+xml
But it seems chrome accepts only text/xml
or application/xml
Not 100% sure why, perhaps you should take it up with google ;p
回答2:
Add doctype.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
来源:https://stackoverflow.com/questions/10145861/make-chrome-display-an-rss-feed-2