如何防止Android返回对我的HTTP请求的缓存响应? [英] How to prevent Android from returning a cached response to my HTTP Request?

查看:199
本文介绍了如何防止Android返回对我的HTTP请求的缓存响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个客户端,该客户端正在对xml数据进行重复的http请求,这些请求随时间而变化。看起来Android堆栈正在缓存我的页面请求并重复返回同一页面。如何确保每次都获得新页?

I'm writing a client that is making repeated http requests for xml data that is changing over time. It looks like the Android stack is caching my page requests and returning the same page repeatedly. How do I make sure it gets a fresh page each time?

- 代码---

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response;
    response = client.execute(request);

InputStream in;
in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));

谢谢,
格里

推荐答案

添加HTTP标头:

Cache-Control: no-cache

并查看是否有效。

这篇关于如何防止Android返回对我的HTTP请求的缓存响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆