class AdvancedWebRequest : HttpWebRequest {
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(AdvancedWebRequest));
public AdvancedWebRequest(string url, CookieContainer cookies = null) {
Create(url);
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22";
Referer = Address.AbsoluteUri;
if (cookies == null) {
CookieContainer = Program.request.CookieContainer;
} else {
CookieContainer = cookies;
}
}
}
这是我想做的事情,因此基本上获取已经设置了一些变量的HttpWebRequest,所以我不能总是自己设置它们。
出现错误:
'System.Net.HttpWebRequest.HttpWebRequest()' is obsolete: 'This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.' \Extensions\AdvancedWebRequest.cs 14 10
有什么建议,不能真正扩展
HttpWebRequest
吗? 最佳答案
您不能从HttpWebRequest
继承,但可以从WebRequest
继承
检查类似问题here的答案。
关于c# - 扩展HttpWebRequest,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15174421/