如果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)。