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?

3
  • Though it is the upside down way, here you can see how it might work :) stackoverflow.com/questions/532211/…
    – Icepickle
    Feb 18, 2016 at 21:19
  • Thank you! I will implement this when I feel like working again Feb 19, 2016 at 0: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. Feb 19, 2016 at 2:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.