Created
February 2, 2014 04:59
-
-
Save Inndy/8763264 to your computer and use it in GitHub Desktop.
Enhanced WebClient class. Cookie, ResponseUri supported.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Net; | |
namespace SpWebClient | |
{ | |
public class SpWebClient : WebClient | |
{ | |
public CookieContainer CookieContainer { get; private set; } | |
public Uri ResponseUri { get; private set; } | |
public SpWebClient() : base() | |
{ | |
this.CookieContainer = new CookieContainer(); | |
this.ResponseUri = null; | |
} | |
public SpWebClient(CookieContainer CookieContainer) : base() | |
{ | |
this.CookieContainer = CookieContainer; | |
this.ResponseUri = null; | |
} | |
public string DownloadString(string Uri, Encoding Encoding) | |
{ | |
return Encoding.GetString(this.DownloadData(Uri)); | |
} | |
public string DownloadString(Uri Uri, Encoding Encoding) | |
{ | |
return Encoding.GetString(this.DownloadData(Uri)); | |
} | |
protected override WebRequest GetWebRequest(Uri address) | |
{ | |
WebRequest request = base.GetWebRequest(address); | |
HttpWebRequest webRequest = request as HttpWebRequest; | |
if (webRequest != null) webRequest.CookieContainer = this.CookieContainer; | |
return request; | |
} | |
protected override WebResponse GetWebResponse(WebRequest request) | |
{ | |
WebResponse response = base.GetWebResponse(request); | |
this.ResponseUri = response.ResponseUri; | |
return response; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment