[REPOST] Dispable Http Caching

  • Thread starter Abhishek Srivastava
  • Start date
A

Abhishek Srivastava

Hello All,

Apologies to everyone, I posted this before but received no response. I
feel someone must have come accross this problem before, and I need a
solution desparately.

I have written a C# program which downloads a file from a webserver on a
daily basis. (http://www.myserver.com/myfile.asp)

The problem is that either the proxy/browser's cache is being used
because my C# program runs successfully but downloads the file from
previous run.

Now, if I open my browser and visit that URL, click refresh plenty of
times, I see the latest file. Now if I run my C# program to download
file, the program also downloads the latest file.

So the either the Browsers or the proxy's cache is being used.

I want to always download the latest file. So my C# program should not
use the cache at all.

How do I make sure that no cache is used (either the browser or proxy).
Here is the code snipped from my program.


HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://www.myserver.com/downloadfile.asp");
WebProxy proxy = new WebProxy();
proxy.Address = new Uri("http://myproxy:8088");
request.Proxy = proxy;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
if (response != null)
{
Stream responseStream = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("UTF-8");
if (reader != null)
{
char[] buffer = new char[BUFFER_SIZE];
int count = reader.Read(buffer, 0, BUFFER_SIZE);
while(count > 0)
{
......
}
}
}

I saw all the properties of the HttpWebRequest and WebProxy classes but
could find anything which disables caching for me.

Thanks for your help in advace.

regards,
Abhishek.
 
J

Joerg Jooss

Abhishek said:
Hello All,

Apologies to everyone, I posted this before but received no response.
I feel someone must have come accross this problem before, and I need
a solution desparately.

I have written a C# program which downloads a file from a webserver
on a daily basis. (http://www.myserver.com/myfile.asp)

The problem is that either the proxy/browser's cache is being used
because my C# program runs successfully but downloads the file from
previous run.

Now, if I open my browser and visit that URL, click refresh plenty of
times, I see the latest file. Now if I run my C# program to download
file, the program also downloads the latest file.

So the either the Browsers or the proxy's cache is being used.

I want to always download the latest file. So my C# program should not
use the cache at all.

How do I make sure that no cache is used (either the browser or
proxy). Here is the code snipped from my program.
[...]

Client-side: Don't use the proxy ;-)

or

Client-side: Set an If-Modified-Since request with the previous day's date.
Server-side: Set appropriate caching headers that force your file to expire
after one day.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top