application/xml 和 text/xml的区别
application/xml and text/xml的区别
经常看到有关xml时提到"application/xml" 和 "text/xml"两种类型, 二者功能一模一样,唯一的区别就是编码格式,text/xml忽略xml头所指定编码格式而默认采用us-ascii编码,而application/xml会根据xml头指定的编码格式来编码:
XML has two MIME types,application/xml and text/xml . These are often used interchangeably, but there is a subtle difference which is why application/xml is generally recommended over the latter.
Let me explain why: according to the standard, text/* -MIME types have a us-ascii character set unless otherwise specified in the HTTP headers. This effectively means that any encoding defined in the XML prolog (e.g. <?xml version=”1.0” encoding=”UTF-8”?>) is ignored. This is of course not the expected and desired behaviour.
To further complicate matters, most/all browser implementations actually implement nonstandard behaviour for text/xml because they process the encoding as if it were application/xml .
So, text/* has encoding issues, and is not implemented by browsers in a standards-compliant manner, which is why using application/* is recommended.
text/xml 和 application/xml的字符集编码问题
关键字: text/xml application/xml
对于Webservice的应用来说,我们通常都是用UTF-8进行网络传输,但也有通过GBK和GB2312传输的情况,但是在我们Webservice的代码实现中,其实是不用关心具体的传输编码的,因为根据RFC2376的定义,Webservice的引擎(axis,cxf,jaxws..)会根据文件传输的ContentType及XML 声明部分定义的编码自动将网络传输过来的内容(字符串)转换成unicode(jvm运行时的字符串都是以unicode形式存在的)。以下是RFC2376的描述:
例子1:
webservice传输的文件
- Content-type: application/xml; charset="utf-16"
- {BOM}<?xml version="1.0"?>
- Content-type: application/xml; charset="utf-16"
- {BOM}<?xml version="1.0"?>
XML and MIME processors会按照utf-16编码处理该文件
例子2:
webservice传输的文件
- Content-type: application/xml
- <?xml version='1.0'?>
- Content-type: application/xml
- <?xml version='1.0'?>
XML processors会按照utf-8编码处理该文件
例子3:
webservice传输的文件
- Content-type: application/xml
- <?xml version='1.0' encoding="ISO-10646-UCS-4"?>
- Content-type: application/xml
- <?xml version='1.0' encoding="ISO-10646-UCS-4"?>
XML processors会按照UCS-4编码处理该文件
例子4:
webservice传输的文件
- Content-type: text/xml
- {BOM}<?xml version="1.0" encoding="utf-16"?>
- Content-type: text/xml
- {BOM}<?xml version="1.0" encoding="utf-16"?>
XML processors会按照us-ascii,而不是utf-16编码处理该文件
参考文档:
application/xml 和 text/xml的区别的更多相关文章
- application/xml和text/xml的区别
XML有两个MIME类型,application/xml和text/xml,它们之间的区别是: text/xml忽略xml文件头中的关于编码的设定(<?xml version="1.0 ...
- 四种常见的 POST 提交数据方式(application/x-www-form-urlencoded,multipart/form-data,application/json,text/xml)
四种常见的 POST 提交数据方式(application/x-www-form-urlencoded,multipart/form-data,application/json,text/xml) 转 ...
- 解决"415 Cannot process the message because the content type 'application/x-www-form-urlencoded' was not the expected type 'text/xml; charset=utf-8'"
wcf basicHttpBinding content-type text/xml;charset=utf-8 wsHttpBinding 'application/soap+xml; ch ...
- solr File Upload "Unsupported ContentType: application/vnd.ms-excel Not in: [application/xml, application/csv, application/json, text/json, text/csv, text/xml, application/javabin]",
今天在用solr管理界面导入文件时报错:"Unsupported ContentType: application/vnd.ms-excel Not in: [application/xm ...
- Webservice报错客户端发现响应内容类型为“application/json;charset=UTF-8”,但应为“text/xml”。
控制台对接Webservice正常,同样的方法在Web项目上报错: 客户端发现响应内容类型为“application/json;charset=UTF-8”,但应为“text/xml”.请求失败,错误 ...
- android 中theme.xml与style.xml的区别
from://http://liangoogle.iteye.com/blog/1848448 android 中theme.xml与style.xml的区别: 相同点: 两者的定义相同. <r ...
- php接收json格式数据(text/xml)
在API服务中,目前流行采用json形式来交互. 给前端调用的接口输出Json数据,这个比较简单,只需要组织好数据,用json_encode($array) 转化一下,前端就得到json格式的数据. ...
- "SQL Server does not handle comparison of NText, Text, Xml, or Image data types."
"SQL Server does not handle comparison of NText, Text, Xml, or Image data types." sql2000 ...
- MyBatis Mapper.xml文件中 $和#的区别
MyBatis Mapper.xml文件中 $和#的区别 网上有很多,总之,简略的写一下,作为备忘.例子中假设参数名为 paramName,类型为 VARCHAR . 1.优先使用#{paramN ...
随机推荐
- SharePoint 数据库管理-PowerShell
1. 显示所有SharePoint数据库 Get-SPDatabase –ServerInstance "SP2010\SQLSharePoint" 2. 获取指定的数据库 $da ...
- Tomcat服务器启动失败:Could not publish server configuration for Tomcat v8.0 Server at localhost. Multiple Contexts have a path of
在eclipse中使用Tomcat8.0时,出现了如下错误: 解决办法: 在建立Tomcat服务时,eclipse会自动生成一个Servers的项目. 在这个项目中,找到你部署项目的服务文件夹. 在这 ...
- HTTPS 通俗简介
为什么需要HTTPS 9个问题搞懂 https 来源 HTTP是明文传输的,也就意味着,介于发送端.接收端中间的任意节点都可以知道你们传输的内容是什么.这些节点可能是路由器.代理 等. 举个最常见的例 ...
- Vue.js 源码学习笔记 - 细节
1. this._eventsCount = { } 这是为了避免不必要的深度遍历: 在有广播事件到来时,如果当前 vm 的 _eventsCount 为 0, 则不必向其子 vm 继续传播该 ...
- apache的<directory> 语句以及属性的含义
在整完apache和tomcat的之后我觉得有必要把<directory>和它下面的属性捋顺一下 如何访问根目录下的目录http://192.168.1.12/test/ 第一.缺省apa ...
- Android Mms专题之:Mms源码结构
从软件的功能角度来讲,Mms分为对话列表,消息列表,短信编辑,彩信编辑,短信显示,彩信显示和配置. 从实现的角度来看,它分为GUI展示层,发送/接收,彩信解析,彩信附件,信息数据等,这些分类对应着源码 ...
- (转)spring hibernate properties详解
转载地址:http://blog.sina.com.cn/s/blog_692d0a650100xyqx.html Hibernate配置属性 hibernate.dialect:一个Hibernat ...
- 3.2 shell输入输出
shell输入与输出: read : read语句可以从键盘或者文件的某一行文本中读入信息,并将其赋值给一个变量. read var1 var2 ... 若只指定了一个变量,那么read将 ...
- python type metaclass
在python中一切皆对象, 所有类的鼻祖都是type, 也就是所有类都是通过type来创建. 传统创建类 class Foo(object): def __init__(self,name): se ...
- 【MVC】View的使用
/Views/_ViewStart.cshtml 文件会在其他视图文档被加载之前被载入,代码如下: @{ Layout = "~/Views/Shared/_Layout.cshtml&qu ...