2014-02-24 101 views
1
// 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); 

當我做一個服務器調用,它帶來的數據...我第二次調用它,它帶來了它的緩存..和不調用服務器... 我怎樣才能解決這一問題?安卓避免緩存

我不想緩存。

回答

4

您可以添加一個HTTP標頭對您的請求:Cache-Control: no-cache

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

非常感謝問題修復 – user3278732

1

您可以添加一個HTTP標頭,並具有:

Cache-Control: no-cache 

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

訪問 http://developer.android.com/reference/android/net/http/HttpResponseCache.html

+0

非常感謝問題修復 – user3278732

+0

@ user3278732如果您發現此答案有幫助,然後根據SO標準,您應該通過投票贊成或接受讚賞。 –

+0

投票需要15聲望,我還沒有它 – user3278732