Mono Class Library: System.Net Namespace

System.Net.WebRequest Class

Makes a request to a Uniform Resource Identifier (URI). [Edit]

See Also: WebRequest Members

System.Object
     System.MarshalByRefObject
          System.Net.WebRequest

public abstract class WebRequest : MarshalByRefObject, System.Runtime.Serialization.ISerializable

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

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:

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]

Example

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

Requirements

Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.x.x, 1.0.5000.0, 2.0.0.0