The System.Net.WebRequest class handles any HTTP or HTTPS requests that your application makes. By default, it uses the Internet Explorer proxy settings and will used a cached copy of a page (subject to the age of the page) instead of requesting the page from the server.
If you find you need to change the caching policy or configure a proxy manually, you will need to use the following code:
Firstly lets add the using statements for the namespaces that contain the classes we need to use.
using System.Net;
using System.Net.Cache;
If you are behind a proxy server, configure the proxy details first.
WebProxy proxy = new WebProxy("192.168.1.10");
proxy.Credentials = new NetworkCredential("User", "Password", "Domain");
If you want to modify the Caching policy, then you need to set the DefaultCachePolicy property.
WebRequest.DefaultCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
If you configured a WebProxy, set it as the default proxy to be used by the WebRequest class.
WebRequest.DefaultWebProxy = proxy;
This article was published on the 24th December 2007