我应该为XML网站地图发送什么Content-Type值?

前端之家收集整理的这篇文章主要介绍了我应该为XML网站地图发送什么Content-Type值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想我应该发送“text / xml”,但后来我读到,我应该发送“application / xml”。有关系吗?有人可以解释差别吗?
如果charset参数为ommitted,则 difference between text/xml and application/xml是缺省字符编码:

Text/xml and application/xml behave differently when the charset
parameter is not explicitly specified. If the default charset (i.e.,
US-ASCII) for text/xml is inconvenient for some reason (e.g.,bad web
servers),application/xml provides an alternative (see “Optional
parameters” of application/xml registration in Section 3.2).

对于text/xml

Conformant with [RFC2046],if a text/xml entity is received with
the charset parameter omitted,MIME processors and XML processors
MUST use the default charset value of “us-ascii”[ASCII]. In cases
where the XML MIME entity is transmitted via HTTP,the default
charset value is still “us-ascii”.

对于application/xml

If an application/xml entity is received where the charset
parameter is omitted,no information is being provided about the
charset by the MIME Content-Type header. Conforming XML
processors MUST follow the requirements in section 4.3.3 of [XML]
that directly address this contingency. However,MIME processors
that are not XML processors SHOULD NOT assume a default charset if
the charset parameter is omitted from an application/xml entity.

因此,如果省略charset参数,则text / xml的字符编码为US-ASCII,而使用application / xml,可以在文档本身中指定字符编码。

现在在互联网上的一个经验法则是:“严格输出,但容忍输入。”这意味着确保在通过互联网传递数据时尽可能地满足标准。但是建立一些机制来忽略错误或在通过互联网接收和解释数据时猜测。

所以在你的情况下,只是选择两种类型之一(我推荐application / xml),并确保正确指定使用的字符编码(我建议使用相应的默认字符编码,以安全,所以在application / xml使用情况下UTF-8或UTF-16)。

原文链接:https://www.f2er.com/xml/294144.html

猜你在找的XML相关文章