如何选择 Application/XML 或 Text/XML 作为媒体类型?
How to choose either Application/XML or Text/XML as mediatype?
我一直在学习jax-rs。我的问题是我不知道如何选择 application/XML 或 text/XML,即使我在 Internet 上阅读了更多关于它们的文章。谁能简单描述一下 application/XML 支持什么,不支持什么?为什么我应该使用 text/XML?
我想他们在这里回答了你的问题What's the difference between text/xml vs application/xml for webservice response
在实践中,这一切都取决于 HTTP 请求中的 Accept header 的值,我们用它来 return 漂亮的格式 XML 当请求 Accept header includes text/xml and minified single lined XML when the request Accept header includes application/xml, 当有疑问时问问自己谁将阅读响应,应用程序或人类?
text/xml
媒体类型是 媒体类型的 别名。
查看RFC 7303了解详情:
9.1. application/xml Registration
Type name: application
Subtype name: xml
[...]
The registration information for text/xml
is in all respects the same
as that given for application/xml above (Section 9.1), except that
the "Type name" is "text".
在 JAX-RS 中,您可以使用以下内容同时支持:
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public Response foo() {
...
}
w3.org 建议使用 application/xml
text/xml
已弃用
我一直在学习jax-rs。我的问题是我不知道如何选择 application/XML 或 text/XML,即使我在 Internet 上阅读了更多关于它们的文章。谁能简单描述一下 application/XML 支持什么,不支持什么?为什么我应该使用 text/XML?
我想他们在这里回答了你的问题What's the difference between text/xml vs application/xml for webservice response
在实践中,这一切都取决于 HTTP 请求中的 Accept header 的值,我们用它来 return 漂亮的格式 XML 当请求 Accept header includes text/xml and minified single lined XML when the request Accept header includes application/xml, 当有疑问时问问自己谁将阅读响应,应用程序或人类?
text/xml
媒体类型是 媒体类型的 别名。
查看RFC 7303了解详情:
9.1. application/xml Registration
Type name: application
Subtype name: xml
[...]
The registration information for
text/xml
is in all respects the same as that given for application/xml above (Section 9.1), except that the "Type name" is "text".
在 JAX-RS 中,您可以使用以下内容同时支持:
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public Response foo() {
...
}
w3.org 建议使用 application/xml
text/xml
已弃用