Android避免缓存

use*_*732 2 networking android caching http

// 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);
Run Code Online (Sandbox Code Playgroud)

当我进行服务器调用时,它会带来数据......第二次我调用它,它会将其缓存...并且不会调用服务器...我该如何解决这个问题?

我不想要缓存.

Nik*_*iko 5

您可以在请求中添加以下HTTP标头: Cache-Control: no-cache

httpGet.addHeader("Cache-Control", "no-cache");
Run Code Online (Sandbox Code Playgroud)