哪种MIME类型更适合确保与RSS阅读器和其他抓取工具兼容?
选项似乎有:
- text/xml
- text/rss+xml
有趣的是Stackoverflow使用的是text/html。
哪种MIME类型更适合确保与RSS阅读器和其他抓取工具兼容?
选项似乎有:
有趣的是Stackoverflow使用的是text/html。
其他评论者指出单一正确的 MIME 类型是 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(以偏好降序排列)。
q
参数来指示,因此为了达到期望的效果,最好发送Accept: application/rss+xml, application/rdf+xml, application/atom+xml, application/xml;q=0.9, text/xml;q=0.8
,它的意思是“首选任何正确的提要MIME类型,如果无法提供,则首选application/xml
,如果仍然无法提供,则首选text/xml
,否则,请给我你有的”。 - Magnus HoffAccept
头的两种形式,它们都返回了text/xml
。我使用了以下命令:curl -s -H 'Accept: application/rss+xml, application/rdf+xml, application/atom+xml, application/xml;q=0.9, text/xml;q=0.8' -H 'Content-Type: application/rss+xml' -I $f
。 - Kai Carver这里有一个实用的答案:无论“正确”的答案是什么(显然对此有争议),text/xml
是目前在野外流行的几乎所有热门Feeds使用的类型。
以下是我检查过的一些:
$ 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
因此,您可以确信常用的RSS客户端会正确解释text/xml
。
text/xml
,2个 application/xml
,1个 text/html
和1个 application/rss+xml
。对于https://savage.love/feed/,我也会获得`application/rss+xml`,对于http://feeds.serialpodcast.org/serialpodcast,我会获得`application/xml`--虽然它作为`<link rel="alternate" type="application/rss+xml" title="Podcast" href="http://feeds.serialpodcast.org/serialpodcast"/>` 进行链接等等。所以,我认为“几乎全部”这个说法并不公平。 - lindes最正确的是 application/rss+xml
最兼容的是 application/xml
根据 W3C:
RSS 源应该使用 application/rss+xml(RSS 1.0 是 RDF 格式,因此也可以使用 application/rdf+xml)。Atom 源应该使用 application/atom+xml。或者,为了与广泛部署的 Web 浏览器兼容,这些源之一可以使用更常见的 XML 类型——最好使用 application/xml。
https://validator.w3.org/feed/docs/warning/UnexpectedContentType.html
application/rss+xml
没有任何实际的兼容性问题,因此使用xml
媒体类型是没有意义的。 - Mikko Ohtamaa你可以使用text/xml
,但正确的MIME类型应该是application/rss+xml
。
application/feed+json
text/xml 是唯一正确的答案。Mime类型是一个基于注册的系统。有一个由IANA(互联网数字分配机构)管理的官方列表,位于http://www.iana.org/assignments/media-types/media-types.xhtml
application/rss+xml
从未在IANA注册。该申请曾于很久以前过期。
https://www.ietf.org/archive/id/draft-nottingham-rss-media-type-00.txt这也是Debian不正确地使用RSS MIME类型的原因
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=605250 - tcitapplication/rss+xml
不是注册类型,因此不是“正确”的;(b)包括W3C在内的各种组织仍然推荐它(例如,请参见https://validator.w3.org/feed/docs/warning/UnexpectedContentType.html);(c)我认为之所以没有被接受是因为起草规范的质量不够好。也许需要重新制定/提交??尽管希望情况不是这样,但还是点赞。 - lindes
application/rss+xml
,Google Chrome浏览器不会美化在选项卡中浏览的XML源代码,但如果我使用text/xml
,它会进行美化。只是说一下。 - DrLightman