致命错误:1:1:prolog中不允许内容 [英] Fatal Error :1:1: Content is not allowed in prolog
问题描述
我正在使用Java,而我正试图从某些http链接获取XML文档。我正在使用的代码是:
I'm using Java and i'm trying to get XML document from some http link. Code I'm using is:
URL url = new URL(link);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
Document doc = null;
CountInputStream in = new CountInputStream(url.openStream());
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
不要注意 CountInputStream
,它是一些像常规输入流一样的特殊类。
Don't pay attention at CountInputStream
, it's some special class acting like regular input stream.
使用上面的代码,我有时会收到错误致命错误:1:1:prolog中不允许内容
。我认为这与xml格式错误有关,但我不知道如何修复它。
Using the code above, I sometimes got error Fatal Error :1:1: Content is not allowed in prolog
. I assume that is has something to do with bad format of xml, but I have no idea how to fix it.
推荐答案
我正在将我的评论转为答案,因此可以接受并且这个问题不再没有答案。
最可能的原因是是一个格式错误的回复,其中包含初始<?xml ...>
之前的字符。因此,请查看通过HTTP传输的文档,并在服务器端修复此问题。
The most likely cause of this is a malformed response, which includes characters before the initial <?xml …>
. So please have a look at the document as transferred over HTTP, and fix this on the server side.
这篇关于致命错误:1:1:prolog中不允许内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!