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

标签 xml mime-types sitemap xml-sitemap

我以为我应该发送“text/xml”,但后来我读到我应该发送“application/xml”。有关系吗?谁能解释一下区别?

最佳答案

difference between text/xml and application/xml如果省略 charset 参数,则为默认字符编码:

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是字符编码可以在文档本身中指定。

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

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

关于xml - 我应该为我的 XML 站点地图发送什么 Content-Type 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3272534/

相关文章:

java - JAXB:编码时多态性和忽略类作为类型

python - 在python中按带有任何前缀的标签解析xml节点子列表

php - ics 文件 mime 类型

java - 当使用 image/tiff 作为 contentType 时,contentDisposition 附件而不是内联

xml - 站点地图 XML 和 PDF

xml - 不包含零的getXpathCount

ios - AFNetworking 2 - 从 NSString 获取 UIImage

http - 如何在接受 header 字段中指定接受具有特定内容类型的多部分/相关内容类型的正文部分

.net - 如何使用 Visual Basic 将一些 XML 插入到 XDocument 中?

sitemap - 每次提交新文章后都要ping google sitemap?