-1

It's a very big problem and it's really bothering me . I've a webservice that I get my data from it via josn , I need my data to be update .

The problem is this ,I open my application , it connects to webservice and it gets very old data , I remove tha app and installed it again ,cleared cache and data, nothing works and it still get old data.

How can I solve it ? this is the code that gets data :

public class Spots_tab1_json {
static String response = null;
public final static int GET = 1;
public final static int POST = 2;

public Spots_tab1_json() {

}
public String makeServiceCall(String url, int method) {
    return this.makeServiceCall(url, method, null);
}
public String makeServiceCall(String url, int method,
        List<NameValuePair> params) {
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpEntity httpEntity = null;
        HttpResponse httpResponse = null;
        if (method == POST) {
            HttpPost httpPost = new HttpPost(url);
            if (params != null) {
                httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
            }
            httpResponse = httpClient.execute(httpPost);
        } else if (method == GET) {
            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);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return response;

}

}

thanks

mohsen
  • 451
  • 2
  • 6
  • 15

2 Answers2

0

Try adding a Cache-Control header to your request with the value no-cache, e.g. httpGet.addHeader("Cache-Control", "no-cache"). HttpGet and HttpPost both inherit AbstractHttpMessage, so the method is available in both classes.

hanspeide
  • 2,819
  • 4
  • 25
  • 33
-1

When you create new HTTP you have to log out first use following code to disconnect

client.getConnectionManager().closeExpiredConnections();
client = null;

and then create new HTTP connection

Maveňツ
  • 1
  • 12
  • 50
  • 89
Boldbayar
  • 862
  • 1
  • 9
  • 22