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 ...
随机推荐
- L224 词汇题
Elaborate 精心的 preparations were being made for the Prime Minister’s official visit to the four forei ...
- Translating Skills(1)
本文是参加公司英语翻译培训的课程.做此记录,以防忘记. ------------------------------------------------------------------------ ...
- Windows下使用Nexus搭建pypi私服
Nexus之前一直作为maven的私服而被大家所熟知,但是其实nexus可以做很多种仓库的私服,官网的说明就揭示了一切,真是又方便又强大的开源工具. 首先下载安装nexus,地址: https://w ...
- flash存储原理
norflash 带有 SRAM接口,有足够的地址引脚来寻址,可以很容易地存取其内容每一字节:nandflash器件使用复杂的IO口串行的存取数据,读写操作采用512字节的块(也就是读/写某个字节,必 ...
- App Transfer:苹果允许iOS App从一个开发者帐号转至另一个开发者账号
App Transfer:苹果允许iOS App从一个开发者帐号转至另一个开发者账号 苹果在WWDC上宣布超过30万的开发者为iOS平台开发超过90万的应用,你可能会想到有人想出售或者购买app. 现 ...
- HDU 3376
http://acm.hdu.edu.cn/showproblem.php?pid=3376 题意:一个矩阵,每个点有价值,起点左上角终点右下角,每次只能走当前点的下一点或右一点,从起点走到终点,再从 ...
- CentOS7安装OpenStack(Rocky版)-06.安装Neutron网络服务(控制节点)
上一章介绍了独立的nova计算节点的安装方法,本章分享openstack的网络服务neutron的安装配制方法 ------------------- 完美的分割线 ----------------- ...
- Linux删除Screen
screen screen命令是用来解决远程运行服务器中程序时无法退出的尴尬问题. 介绍 有详细的一篇文章 linux screen 命令详解 问题 文章较老,难免有问题. 比如某用户评论: Ctrl ...
- POJ:2386 Lake Counting(dfs)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40370 Accepted: 20015 D ...
- 51Nod:1268 和为K的组合
1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 给出N个正整数组成的数组A,求能否从中选出若干个,使他们的和为K.如果可以 ...