I am trying to cast a class that inherits WebRequest to HttWebRequest (since I cannot inherit HttpWebRequest directly) but I get that the cast is not valid. Any idea how I can get a HttpWebRequest from my instance?
This is the code:
static void Main(string[] args)
{
WebRequest wr = new WR("bla");
HttpWebResponse webres = (HttpWebResponse) wr; // this fails
Console.ReadKey();
}
public class WR : WebRequest
{
private string bla;
private Uri url;
public WR(string x)
{
bla = x;
}
public override Uri RequestUri
{
get { return this.url; }
}
}