如何防止 Android 返回对我的 HTTP 请求的缓存响应?
我正在编写一个客户端,它对随时间变化的 xml 数据发出重复的 http 请求。看起来 Android 堆栈正在缓存我的页面请求并重复返回同一页面。如何确保每次都会获得新页面?
-- 代码 ---
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));
谢谢, 格里
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?
-- code ---
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));
Thanks,
Gerry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 URL 末尾附加未使用的参数:
其中
someRandomString()
可能涉及当前时间。它很粗糙,但它几乎可以保证工作,无论所有可能导致“正确”解决方案失败的外部因素如何,例如配置错误或有缺陷的代理。
Append an unused parameter on the end of the URL:
where
someRandomString()
probably involves the current time.It's crude, but it's pretty much guaranteed to work regardless of all the outside factors that can make a "proper" solution fail, like misconfigured or buggy proxies.
添加 HTTP 标头:
并查看是否有效。
add a HTTP header:
and see if that works.
提示:获取随机字符串
Hint: to get the random string