0

I am trying to make a Window Form application that requires to send pre-check and post-check tokens back to the server using HttpWebRequest. I have looked on google and all the answers I get are for ASP.NET applications. One example I have found on MSDN (https://msdn.microsoft.com/en-us/library/system.net.webrequest.cachepolicy%28v=vs.110%29.aspx) seems to steer me in the right direction, but when I take out my Header capture tool, I still see that the cache control is still set to no cache. I have tried adding

request.Headers.Add("Cache-control", "public")

to my code but I still get the same error in Fiddler I also tried using the information in the MSDN article, but the application still does not cache. How do I get the program to work?

Here is my code

            // create new webrequest object
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
            // reuse old headers 
            //request.Headers = response_headers;
            HttpRequestCachePolicy policy = new


            request.Referer = referalUrl;
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            request.Headers.Add("Accept-Encoding", "gzip,deflate");
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
            request.CookieContainer = cookieJar;
            // no data to enter

            HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // this is where I run into problems.

Any ideas?

Tom Morison
  • 564
  • 1
  • 8
  • 26
  • Though it is the upside down way, here you can see how it might work :) http://stackoverflow.com/questions/532211/how-to-clear-the-cache-of-httpwebrequest – Icepickle Feb 18 '16 at 21:19
  • Thank you! I will implement this when I feel like working again – Tom Morison Feb 19 '16 at 00:55
  • Nope, I tried different caching policies and I still get stuck with the "no-cache" error message in fiddler no matter what I do. – Tom Morison Feb 19 '16 at 02:03

0 Answers0