Android的避免缓存 [英] Android avoid caching
本文介绍了Android的避免缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// http client
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
// Checking http request method type
if (method == POST) {
HttpPost httpPost = new HttpPost(url);
// adding post params
if (params != null) {
httpPost.setEntity(new UrlEncodedFormEntity(params));
}
httpResponse = httpClient.execute(httpPost);
} else if (method == GET) {
// appending params to url
if (params != null) {
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);
httpResponse = httpClient.execute(httpGet);
}
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
当我做一个服务器调用,它带来的数据...我第二次调用它,它带来的缓存..和不调用服务器...
我该如何解决这个问题?
When I make a server call, it brings data...second time i call it, it brings it cached.. and doesn't call server... how can i fix this?
我不想缓存。
推荐答案
您可以下面的HTTP标头添加到您的要求:的Cache-Control:no-cache的
You can add following HTTP header to your request: Cache-Control: no-cache
httpGet.addHeader("Cache-Control", "no-cache");
这篇关于Android的避免缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文