是否最好使用一种 MIME 类型来确保与 RSS 阅读器和其他抓取工具的兼容性?
选项似乎是:
有趣的是 Stackoverflow 使用的是 text/html。
其他评论者指出,唯一正确的哑剧类型是
application/rss+xml,
。
但是,如果您要为客户端设置接受标头,则
Accept: application/rss+xml, application/rdf+xml;q=0.8, application/atom+xml;q=0.6, application/xml;q=0.4, text/xml;q=0.4
可能是一个不错的选择,因为它声明它接受 RSS、Atom 和 XML(按降序或优先顺序)。
这是一个务实的答案:无论“正确”答案是什么(显然对此存在争议),
text/xml
几乎是所有在野外流行的饲料所使用的类型。
以下是我检查过的一些:
$ for f in \
https://feeds.feedburner.com/TechCrunch/ \
http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml \
http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml \
https://daringfireball.net/thetalkshow/rss \
http://www.npr.org/rss/podcast.php?id=381444908 \
http://feeds.serialpodcast.org/serialpodcast \
http://podcasts.joerogan.net/feed \
https://feeds.feedburner.com/thetimferrissshow \
http://feed.thisamericanlife.org/talpodcast ; do \
curl -s -I $f | fgrep -i Content-Type: ; done
content-type:text/xml; charset=UTF-8
Content-Type: text/xml
Content-Type: text/xml
Content-Type: text/xml;charset=UTF-8
Content-Type: text/xml;charset=UTF-8
Content-Type: text/xml; charset=UTF-8
Content-Type: text/xml; charset=UTF-8
content-type:text/xml; charset=UTF-8
Content-Type: text/xml; charset=UTF-8
因此您可以确定
text/xml
将被常用的 RSS 客户端正确解释。
最正确是
application/rss+xml
最兼容的是
application/xml
根据 W3C:
RSS 提要应作为 application/rss+xml 提供(RSS 1.0 是 RDF 格式,因此它可以作为 application/rdf+xml 来代替)。原子 feeds应该使用application/atom+xml。或者,对于 与广泛部署的网络浏览器、任何这些源的兼容性 可以使用一种更通用的 XML 类型 - 最好 应用程序/xml。
https://validator.w3.org/feed/docs/warning/UnexpectedContentType.html
MIME 应用程序/rss+xml 以确保安全。这就是我用的。
可以使用text/xml
,但正确的MIME类型是
application/rss+xml
。
application/feed+json