WebRequest ignoring cache

  • Thread starter Thread starter Pete Davis
  • Start date Start date
P

Pete Davis

First of all, I apologize. I wanted to post this in
microsoft.public.dotnet.framework (as it's a bit more appropriate there),
but Outlook Express is suddenly giving me errors whenever I go to that
newsgroup and I have to restart OE.

I'm using WebRequest and I want to bypass any caching in the proxy server.
Unfortunately, I don't have a proxy to test with.

My understanding is that I just need to pass a pragma: no-cache and
cache-control: no-cache (to avoid caching in the first place) in the header.
Do I simply add the headers as shown in the code below? Or do I need to do
something else?

WebRequest req = WebRequest.Create(url);
if (null != proxy)
{
req.Proxy = proxy;
}
using (WebResponse response = req.GetResponse())
{
req.Headers.Add("pragma", "no-cache");
req.Headers.Add("cache-control", "no-cache");
using (Stream stream = response.GetResponseStream())
{...


Thanks.

Pete
 
Nevermind, figured it out from a second google search. I must have
misspelled something in the first because I was getting completely offtopics
responses.

Anyway, the code I guess was right except that I should be using
req.Headers.Set() instead of add. I'm not sure it matters, but that's what
the sample code did.

Pete
 
Back
Top