App appears to cache http data
<p>I'm writing an auto-updater for applications that my company has developed for internal use. The applications are stored on an external web server. The problem I am having is that every download attempt retrieves old data that is no longer on the server. If I use the phone's browser (or my PC browser), the new data downloads correctly. I am downloading APK's and JSON files.</p>

<p>I have tried two different methods (found both on SO), both inside an AsyncTask doInBackground:</p>

<pre><code>HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
request.addHeader("deviceId", "xxxxx");
String result = "";
ResponseHandler&lt;String&gt; handler = new BasicResponseHandler();
result = httpclient.execute(request, handler);
httpclient.getConnectionManager().shutdown();
return result;
</code></pre>

<p>and:</p>

<pre><code>URL url = new URL(sUrl[0]);
URLConnection connection = url.openConnection();
connection.setDefaultUseCaches(false);
connection.connect();

// this will be useful so that you can show a typical 0-100% progress bar
int fileLength = connection.getContentLength();

//download the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(downloadDir + "/" + name);

byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
   total += count;
   // publishing the progress....
   publishProgress((int) (total * 100 / fileLength));
   output.write(data, 0, count);
}

output.flush();
output.close();
input.close();
</code></pre>

<p>I have tried this on two phones. The first download is fine, then after that the phones redownload the first downloaded version. I doubt that the caching is on the server, because it only happens inside my app. Also, I am definately not reading old files; I have checked for that and tried downloading into strings. What confuses me is that I have used the first above method in a different app and it works perfectly. Could it be a caching issue? And if so, how do I force it to clear old data? Renaming the files on the server resolves this problem, but there are some files that can't have their names change, and besides that renaming files is a rather ugly solution.</p>
