报错内容为:
Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
网上所述总结来说就是解析内容内包含BOM。这个标记是看不到的,流里面有这个标记而已。
BOM:Byte Order Mark,中文名字节顺序标记。UCS规范建议在传输字节流前,先传输BOM来判断字节顺序。
其实UTF-8是不需要用BOM来表明字节顺序的,但是可以 用BOM来表明编码方式。BOM的UTF-8编码是EF BB BF,所以呢,如果接受者收到EF BB BF开头的字节流,就说明它是UTF-8编码了。
解决办法:
如果解析的是文件:
可以用UltraEdit或者EmEditor打开XML,然后另存为,保存的时候有选项是以无BOM的UTF-8保存还是以有BOM的UTF-8保存。
如果是从远程请求回来的内容:
那么你把返回的流New为字符串,是看不到BOM的,但是你必须截取你需要的内容:
if(null != result && !"".equals(result)){ if(result.indexOf("<") != -1 && result.lastIndexOf(">") != -1 && result.lastIndexOf(">") > result.indexOf("<")) result = result.substring(result.indexOf("<"), result.lastIndexOf(">") + 1); }
也有说是DOM4J版本较低引起的,但是我看了一下我是用的版本是1.6.1,所以排除此类可能,但是在实际中我还是建议使用最新稳定版本来进行开发。
更新
今天看日志,发现我的异常不是因为BOM头引起的,幸好我也打印了收到的内容,我一看,我去,服务器在自己处理失败以后直接返回个 error字符串,mian了一下,果然出错,这坑爹的玩儿。
public static void main(String[] args) throws DocumentException { String str = "error"; Document doc = DocumentHelper.parseText(str); System.out.println(doc.asXML()); }
相关推荐
报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用l
NULL 博文链接:https://rayoo.iteye.com/blog/1973032
设置隐试打开PPT报错 Hiding the application window is not allowed
Android中有许多的xml定义文件,比如动画、图形等等。 刚接触android时,看见这些,通常时一头雾水,只有无尽的搜索... 这个文档,对这些xml中的属性进行了一定的整理。可以参考一下。
Unity2018 可用的Behvior Designer。 低版本的导入Unity2018打开Designer Editor会报错: CreateScriptableObjectInstanceFromType is not allowed to be called during serialization
Host 主机名 is not allowed to connect the mysql server 原因:没有授权远程访问mysql 解决方法: cmd 中运行mysql -u root -p(如果报mysql 不是内部或外部命令,找到安装mysql对应的bin文件夹运行mysql.exe,...
directories that will not be allowed to be processed by Diskeeper. Event Logging ------------- Diskeeper records information about its activity in two ways. First, general information about ...
opencv-2.4.9/modules/gpu/src/nvidia/core/NCVPixelOperations.hpp(51): error: a storage class is not allowed in an explicit specialization 这是由于NCVPixelOperations.hpp的问题,只要替换opencv-2.4.9/...
Android WebView 报 Not allowed to load local resource错误的解决办法 博客地址:http://blog.csdn.net/yuzhiqiang_1993/article/details/76228541
主要介绍了基于Springboot2.3访问本地路径下静态资源的方法(解决报错:Not allowed to load local resource),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着...
message from server: “Host ‘****’ is not allowed to connect to this MySQL server 1:在登录mysql服务器 2:执行:GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ WITH GRANT OPTION //赋予任何主机访问数据的...
keil 编译时出现错误和警告总结 中国电子DIY之家
Error:(25, 5) Integer types not allowed (at 'android:textSize' with value '12'). 代码 <style name=HorizontalBtnLayout> <item name=android:layout_height>match_parent <item name=android:...
java.sql.SQLException: null, message from server: “Host ‘223.72.41.7’ is not allowed to connect to this MySQL server” 客户端访问时报错: 解决方法: 1,登陆服务器 mysql> use mysql; //用mysql ...
keil常见错误 keil常见错误 keil常见错误 keil常见错误
nginx: [emerg] “proxy_cache_path” directive is not allowed here in /etc/nginx/conf.d/default.conf:29 提示意思“proxy_cache_path指令不被允许”,在官网上查找了相关说明,也没有发现问题,最后看应用范围...
到如一些小脚本很少报错,但最近导入一个10+M的SQL脚本,却重复报错: Error occured at:2014-03-24 11:42:24 Line no.:85 Error Code: 2006 - MySQL server has gone away 最终找到原因,原来是MySQL导入大批量...
"Host 'localhost' is not allowed to connect to this MySQL server" 的原因及解决办法
主要介绍了php采用curl访问域名返回405 method not allowed提示的解决方法,需要的朋友可以参考下
从3GPP协议和UE端行为分析5G gmm cause #27的网络问题