views:

538

answers:

1

I have an HttpWebRequest that I've set the CachePolicy to CacheIfAvailable, and I've set AllowAutoRedirect to false. Now when there is a cache hit, the HttpWebResponse.Status == NotModified, and there is no response stream. I need to know what the cached response is!

If I set the CachePolicy to BypassCache it works just fine. But I need to cache these results.

Can anyone tell me how to retrieve the cached response in the case of a cache hit?

A: 

It turns out that the problem is that I was setting HttpWebRequest.IfModifiedSince (to itself). Yes, the getter for that property is set to always return DateTime.Now, until it is explicitly set. So: request.IfModifiedSince = request.IfModifiedSince; is not a safe no-op. It actually sets a flag saying to actually send the If-Modified-Since HTTP header, which was causing my grief.

Andrew Arnott