Share via


WebRequest Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.

Inheritance Hierarchy

System. . :: . .Object
  System. . :: . .MarshalByRefObject
    System.Net..::..WebRequest
      System.Net. . :: . .FtpWebRequest
      System.Net. . :: . .HttpWebRequest

Namespace:  System.Net
Assembly:  System.Http (in System.Http.dll)

Syntax

'Declaration
Public MustInherit Class WebRequest _
    Inherits MarshalByRefObject _
    Implements IDisposable
public abstract class WebRequest : MarshalByRefObject, 
    IDisposable
public ref class WebRequest abstract : public MarshalByRefObject, 
    IDisposable
[<AbstractClass>]
type WebRequest =  
    class
        inherit MarshalByRefObject
        interface IDisposable
    end
public abstract class WebRequest extends MarshalByRefObject implements IDisposable

The WebRequest type exposes the following members.

Constructors

  Name Description
Protected method WebRequest Initializes a new instance of the WebRequest class.

Top

Properties

  Name Description
Public property ConnectionGroupName When overridden in a descendant class, gets or sets the name of the connection group for the request.
Public property ContentLength When overridden in a descendant class, gets or sets the content length of the request data being sent.
Public property ContentType When overridden in a descendant class, gets or sets the content type of the request data being sent.
Public propertyStatic member DefaultWebProxy Gets or sets the global HTTP proxy.
Public property Headers When overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.
Public property Method When overridden in a descendant class, gets or sets the protocol method to use in this request.
Public property Proxy When overridden in a descendant class, gets or sets the network proxy to use to access this Internet resource.
Public property RequestUri When overridden in a descendant class, gets the URI of the Internet resource associated with the request.
Public property Timeout Gets or sets the length of time, in milliseconds, before the request times out.

Top

Methods

  Name Description
Public methodStatic member Create(String) Initializes a new WebRequest instance for the specified URI scheme.
Public methodStatic member Create(Uri) Initializes a new WebRequest instance for the specified URI scheme.
Public method Dispose() () () () Releases the resources used by the HttpWebRequest.
Protected method Dispose(Boolean) Releases the unmanaged resources used by the HttpWebRequest and optionally releases the managed resources.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Performs clean up operations. (Overrides Object. . :: . .Finalize() () () ().)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetRequestStream When overridden in a descendant class, returns a Stream for writing data to the Internet resource.
Public method GetResponse When overridden in a descendant class, returns a response to an Internet request.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic member RegisterPrefix Registers a WebRequest descendant for the specified URI.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

WebRequest is the abstract base class for the .NET Micro Framework's request/response model for accessing data from the Internet. An application that uses the request/response model can request data from the Internet in a protocol-agnostic manner, in which the application works with instances of the WebRequest class while protocol-specific descendant classes carry out the details of the request.

Requests are sent from an application to a particular URI, such as a Web page on a server. The URI determines the proper descendant class to create from a list of WebRequest descendants registered for the application. WebRequest descendants are typically registered to handle a specific protocol, such as HTTP or FTP, but can be registered to handle a request to a specific server or path on a server.

The WebRequest class throws a WebException when errors occur while accessing an Internet resource. The Status property is one of the WebExceptionStatus values that indicates the source of the error. When Status is WebExceptionStatus..::..ProtocolError, the Response property contains the WebResponse received from the Internet resource.

Because the WebRequest class is an abstract class, the actual behavior of WebRequest instances at run time is determined by the descendant class returned by Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.

Note

Use the Create method to initialize new WebRequest instances. Do not use the WebRequest constructor.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Net Namespace