Java – fatal error: content not allowed in 1:1: Prolog

I'm using Java and I'm trying to get XML documents from some HTTP links The code I use 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);

Do not pay attention to countinputstream. It is a special class, like a regular input stream

Using the above code, I sometimes get fatal errors: 1:1: content is not allowed in Prolog I assume this is inconsistent with the XML format, but I don't know how to solve it

Solution

I turned my comment into an answer, so I can accept this question. This question is no longer unanswered

The most likely cause is the wrong response, which is included in the initial Previous characters So please look at the documents transmitted over HTTP and fix them on the server side

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>