Skip to content

Instantly share code, notes, and snippets.

@sebfia
Created June 20, 2012 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebfia/2959089 to your computer and use it in GitHub Desktop.
Save sebfia/2959089 to your computer and use it in GitHub Desktop.
A web client implementation that extends the System.Net.WebClient by storing cookies for recurring requests.
/// <summary>
/// A web client implementation that extends the System.Net.WebClient by storing cookies for recurring requests.
/// </summary>
public sealed class ExtendedWebClient : WebClient
{
public CookieContainer CookieContainer { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
var webRequest = base.GetWebRequest(address);
var httpWebRequest = webRequest as HttpWebRequest;
if (httpWebRequest != null)
{
(httpWebRequest).CookieContainer = CookieContainer;
}
return webRequest;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment