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不能真正扩展吗?
发布于 2013-03-02 20:38:35
您不能从HttpWebRequest继承,但可以从WebRequest继承
检查类似问题here中的答案。
发布于 2013-03-03 17:47:13
您可以使用如下扩展方法:
public static DoRequest(this HttpWebRequest req){
//do something
}然后你可以像这样调用这个方法:
webrequest.DoRequest();有关更多信息,请查看MSDN页面:http://msdn.microsoft.com/en-us/library/vstudio/bb383977.aspx
https://stackoverflow.com/questions/15174421
复制相似问题