2
// 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?

i don't want caching.

flx
  • 14,146
  • 11
  • 55
  • 70
user3278732
  • 1,694
  • 10
  • 31
  • 67

2 Answers2

6

You can add following HTTP header to your request: Cache-Control: no-cache

httpGet.addHeader("Cache-Control", "no-cache");
Niko
  • 8,093
  • 5
  • 49
  • 85
1

You can add a HTTP header and have :

Cache-Control: no-cache

like

httpPost.addHeader("Cache-Control", "no-cache");
httpGet.addHeader("Cache-Control", "no-cache");

visit http://developer.android.com/reference/android/net/http/HttpResponseCache.html

Jitesh Upadhyay
  • 5,244
  • 2
  • 25
  • 43
  • @user3278732 If you have found this answer as helpful then as per the SO standard, you should appreciate it by either up voting or accepting it. – Paresh Mayani Feb 24 '14 at 13:18