我试图获取一个XML文件,但它似乎已被缓存。
这是我的密码:
URL url = new URL("http://delibere.asl3.liguria.it/SVILUPPO/elenco_xml.asp?rand=" + new Random().nextInt()+"&Oggetto=" + text +"&TipoDocumento="+tipoDocumento);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setDefaultUseCaches(false);
urlConn.setAllowUserInteraction(true);
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestMethod("GET");
urlConn.setRequestProperty("Pragma", "no-cache");
urlConn.setRequestProperty("Cache-Control", "no-cache");
urlConn.setRequestProperty("Expires", "-1");
urlConn.setRequestProperty("Content-type", "text/xml");
urlConn.setRequestProperty("Connection","Keep-Alive");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = new BufferedInputStream(url.openStream());
Document doc = db.parse(is);
doc.getDocumentElement().normalize();
谢谢!
最佳答案
你意识到你没有使用你的HttpURLConnection
,对吧?如果要使用InputStream
获取HttpURLConnection
,则需要调用
InputStream is = new BufferedInputStream(urlConn.getInputStream());
而且,我相信使用Android的Apache HTTPclipse是标准的,因为它是内置的,比标准Java的API要好得多。