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;
}
}
}
This is something I want to do, so basically get the HttpWebRequest with some variables already set, so I must not set them always myself.
Getting error:
'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
Any suggestions, can't HttpWebRequest
be really extended?
In a nutshell, WebRequest—in its HTTP-specific implementation, HttpWebRequest—represents the original way to consume HTTP requests in . NET Framework. WebClient provides a simple but limited wrapper around HttpWebRequest. And HttpClient is the new and improved way of doing HTTP requests and posts, having arrived with .
The default value is 100,000 milliseconds (100 seconds).
The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP.
from a quick check in the object browser HttpWebRequest isn't seem to be disposable. it needs to have IDisposable interface.
You can not inherit fromHttpWebRequest
but you can inherit from WebRequest
Check the answers from the similar question here.
You could use Extension Methods like this:
public static DoRequest(this HttpWebRequest req){
//do something
}
and then you can call this method like this:
webrequest.DoRequest();
For more infos, look at the MSDN Page: http://msdn.microsoft.com/en-us/library/vstudio/bb383977.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With