简体   繁体   中英

How can I fix a unexpected End of Document Exception

I saw the other posts on this site and others but people have solved this different ways and none of them required an authentication to access the XML.

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("some web site");
httpGet.addHeader("Authorization", getAuthHeader());
HttpResponse response = httpclient.execute(httpGet);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();  

Document doc = db.parse(response.getEntity().getContent());

NodeList nodelst = doc.getElementsByTagName("ad");

I know that my HTTP request is fine; its status is 200, but I get this

saxParserException: unexpected end of document

at the line that I have spaced out. Does anyone know how to start from the begining or am I getting a blank file... how can I test for that?

Thanks for your help

the XML looks like this. it is pretty simple

<ads>
<ad>
<id>6</id>
<minViews>10</minViews>
<duration>4</duration>
<actionUrl>
some url
</actionUrl>
<imageUrl>
some url
</imageUrl>
<impressionCount>0</impressionCount>
</ad>
</ads>

Status 200 doesn't have anything to do with the content of the message. There is probably an error in your xml. What does your xml look like?

http://pronto.mersoft.com/pronto/adclick?appKey=sS5fPOH8QSGl0ExQet-pwg&deviceId=12345&adId=6
...
http://pronto.mersoft.com/pronto/image?id=6&appKey=sS5fPOH8QSGl0ExQet-pwg

I believe that the ampersands ( & ) in those lines need to be escaped (as &amp; ) for this to be legal XML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM