为什么android HttpURLConnection缓存输入流结果?
我正在尝试获取 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();
谢谢!
i'm trying to get a xml file but it seems to be cached.
there's my code:
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();
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您意识到您没有使用
HttpURLConnection
,对吧?如果你想使用HttpURLConnection
获取InputStream
,你需要调用另外,我相信在Android中使用Apache HttpClient来处理此类事情是标准的,因为它是内置的 API 比标准 Java 的东西好得多。
You realize you aren't using your
HttpURLConnection
, right? If you want to get theInputStream
using theHttpURLConnection
, you need to callAlso, I believe that it's standard to use Apache HttpClient for this sort of thing with Android, since it's built in and a much better API than the standard Java stuff.
看起来他们有一个有效的 HttpClient 解决方案。 你可以尝试一下,HttpClient 提供了一些更灵活地处理其他问题
It looks like they have a solution with HttpClient that works. You might try it, and HttpClient gives a bit more flexibility with other issues