class XWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri Url)
{
var Request = base.GetWebRequest(Url);
...........
return Request;
}
}
使用:
try
{
XWebClient Client = new XWebClient();
Client.DownloadString(new Uri("badurl:100500"));
}
catch
{
MessageBox.Show("exception");
}
我希望得到一个消息框,但我得到一个未处理的异常。我究竟做错了什么?
异常:System.NotSupportedexception
消息:无法识别 URI 前缀
痕迹:
System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
System.Net.WebRequest.Create(Uri requestUri)
System.Net.WebClient.GetWebRequest(Uri address)
XWebClient.GetWebRequest(Uri Url) в [path]\XWebClient.cs:строка 28
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)