This is the first time I am using HttpURLConnection
in Android.
URL url = null;
HttpURLConnection con = null;
BufferedReader in = null;
try {
url = new URL(companyInfo.getCompanyCurrent());
Log.i(Constant.TAG, "URL:" + url.toString());
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("connection", "close");
con.setUseCaches(false);
con.setDefaultUseCaches(false);
con.setRequestProperty("Cache-Control", "no-cache");
con.setRequestProperty("Cache-Control", "no-store");
con.setRequestProperty( "User-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4" );
int responseCode = con.getResponseCode();
....
So as you see, I have made setUseCaches
and setDefaultUseCaches
as false
and from some of the suggestions on the internet, tried setting "Cache control" as well. The problem is that its still caching results. It refreshes periodically.
- Is there a way delete the cached results?
- Is there a way set cached refresh time?
On a side note I found that if user agent is not set explicitly, for some android versions the desktop URL is hit and for others mobile URL is hit. Any particular reason for that?