0
以下构造方法应将URL中的XML读取到XML Document
对象中。虽然它已经有效,但我仍然怀疑它是正确的。HttpURLConnection的InputStream:何时断开?
// Basic constructor method without exception handling
Feed(URL url) throws IOException, ParserConfigurationException, SAXException {
HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
httpcon.addRequestProperty("User-Agent", "Some User-Agent");
InputStream inStream = httpcon.getInputStream();
httpcon.disconnect();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
doc = builder.parse(inStream);
}
问题:
- 不应该一个第一解析
InputStream
,然后关闭HttpURLConnection
? - 不应该有
httpcon.connect()
之前我试图get
东西从httpcon
?