Created
June 20, 2012 09:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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