Why am I getting "(304) Not Modified" error on some links when using HttpWebRequest?

Posted by Greg on Stack Overflow See other posts from Stack Overflow or by Greg
Published on 2010-04-08T21:30:33Z Indexed on 2010/04/08 21:33 UTC
Read the original article Hit count: 312

Hi,

Any ideas why on some links that I try to access using HttpWebRequest I am getting "The remote server returned an error: (304) Not Modified." in the code?

The code I'm using is from Jeff's post here.

Note the concept of the code is a simple proxy server, so I'm pointing my browser at this locally running piece of code, which gets my browsers request, and then proxies it on by creating a new HttpWebRequest, as you'll see in the code. It works great for most sites/links, but for some this error comes up. You will see one key bit in the code is where it seems to copy the http header settings from the browser request to it's request out to the site, and it copies in the header attributes. Not sure if the issue is something to do with how it mimics this aspect of the request and then what happens as the result comes back?

  case "If-Modified-Since":
     request.IfModifiedSince = DateTime.Parse(listenerContext.Request.Headers[key]);
     break;

I get the issue for example from http://en.wikipedia.org/wiki/Main_Page

thanks

© Stack Overflow or respective owner

Related posts about httpwebrequest

Related posts about 304