Fatal Error :1:1: Content is not allowed in prolog

后端 未结 6 1014
旧时难觅i
旧时难觅i 2021-01-01 09:58

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 = (HttpUR         


        
相关标签:
6条回答
  • 2021-01-01 10:27

    The real solution that I found for this issue was by disabling any XML Format post processors. I have added a post processor called "jp@gc - XML Format Post Processor" and started noticing the error "Fatal Error :1:1: Content is not allowed in prolog"

    By disabling the post processor had stopped throwing those errors.

    0 讨论(0)
  • 2021-01-01 10:30

    It could be not supported file encoding. Change it to UTF-8 for example.

    I've done this using Sublime

    0 讨论(0)
  • 2021-01-01 10:33

    I'm turning my comment to an answer, so it can be accepted and this question no longer remains unanswered.

    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.

    0 讨论(0)
  • 2021-01-01 10:35

    Someone should mark Johannes Weiß's comment as the answer to this question. That is exactly why xml documents can't just be loaded in a DOM Document class.

    http://en.wikipedia.org/wiki/Byte_order_mark

    0 讨论(0)
  • 2021-01-01 10:42

    There are certainly some weird characters (e.g. BOM) or some whitespace before the XML preamble (<?xml ...?>)?

    0 讨论(0)
  • 2021-01-01 10:45

    Looks like you forgot adding correct headers to your get request (ask the REST API developer or you specific API description):

    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.header("Accept", "application/xml")
    connection.setRequestMethod("GET");
    connection.connect();
    

    or

    connection.header("Accept", "application/xml;version=1")
    
    0 讨论(0)
提交回复
热议问题