Mono Class Library: System.Net NamespaceSystem.Net.WebRequest Class |
See Also: WebRequest Members
System.Object
System.MarshalByRefObject
System.Net.WebRequest
|
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
System.Net.WebRequest is an abstract class that models the request side of transactions used for accessing data from the Internet.
Classes that derive from System.Net.WebRequest are required to override the following members of the System.Net.WebRequest class in a protocol-specific manner:
- WebRequest.Method -- Gets or sets the protocol method to use in the current instance.
- WebRequest.RequestUri -- Gets the Uri of the resource associated with the current instance.
- WebRequest.Headers -- Gets or sets the collection of header name/value pairs associated with the request.
- WebRequest.ContentLength -- Gets or sets the content length of the request data being sent.
- WebRequest.ContentType -- Gets or sets the content type of the request data being sent.
- WebRequest.Credentials -- Gets or sets the credentials used for authenticating the client using the current instance.
- WebRequest.PreAuthenticate -- Gets or sets a value that indicates whether to send authentication information with a request for resources.
- WebRequest.GetRequestStream -- Returns a System.IO.Stream for writing data to a resource.
- WebRequest.BeginGetRequestStream(AsyncCallback, object) -- Begins an asynchronous request for a stream in which to write data to be sent in the current request.
- WebRequest.EndGetRequestStream(IAsyncResult) -- Returns a System.IO.Stream for writing data to the resource accessed by the current instance.
- WebRequest.GetResponse -- Returns a response to a request.
- WebRequest.BeginGetResponse(AsyncCallback, object) -- Begins an asynchronous request for a resource.
- WebRequest.EndGetResponse(IAsyncResult) -- Returns a System.Net.WebResponse that contains a response to a specified pending request.
In addition, derived classes are required to support the System.Net.IWebRequestCreate interface.
Note:An application that uses the request/response model can request data be sent from the Internet in a protocol-agnostic manner, in which the application works with instances of the System.Net.WebRequest class while classes that derive from System.Net.WebRequest and implement specific protocols perform the details of the request.
Requests are sent from an application to a particular Uniform Resource Identifier (URI), such as a Web page on a server. Using the URI, the WebRequest.Create(Uri) method creates an instance of a type derived from System.Net.WebRequest to handle the request. The type is selected from the set of registered types. Types may be registered to handle a specific protocol, such as HTTP or FTP, or to handle a request to a specific server or path on a server.
Note: For information on registering types, see WebRequest.RegisterPrefix(string, IWebRequestCreate).The System.Net.WebRequest class throws a System.Net.WebException exception when an error occurs while accessing a resource.
Use the WebRequest.Create(Uri, bool) method to initialize a new instance of a class that derives from System.Net.WebRequest . Do not use the System.Net.WebRequest constructor.
If the environment variable http_proxy is set, this specifies the proxy to be used for HTTP requests; The format of this string is the url of the proxy server.
[Edit]
The following example demonstrates using WebRequest.Create(Uri, bool) to create an instance of System.Net.HttpWebRequest .
C# Example using System; using System.Net; public class WebRequestExample { public static void Main() { // Initialize the WebRequest. WebRequest myRequest = WebRequest.Create("http://www.contoso.com"); // Print the type of the request. Console.WriteLine(myRequest); } }The output is
System.Net.HttpWebRequest
Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.x.x, 1.0.5000.0, 2.0.0.0