System.Net.WebRequest Class

Assembly: System.dll
Namespace: System.Net
Summary
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
C# Syntax:
[Serializable]
public abstract class WebRequest : MarshalByRefObject, ISerializable
Remarks
WebRequest is the abstract base class for the .NET 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 WebException.Status property is one of the WebExceptionStatus values that indicates the source of the error. When WebException.Status is WebExceptionStatus.ProtocolError, the WebException.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 WebRequest.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 WebRequest.Create method to initialize new WebRequest instances. Do not use the WebRequest constructor.

Notes to inheritors: When you inherit from WebRequest, you must override the following members: WebRequest.Method, WebRequest.RequestUri, WebRequest.Headers, WebRequest.ContentLength, WebRequest.ContentType, WebRequest.Credentials, WebRequest.PreAuthenticate, WebRequest.GetRequestStream, WebRequest.BeginGetRequestStream, WebRequest.EndGetRequestStream, WebRequest.GetResponse, WebRequest.BeginGetResponse, and WebRequest.EndGetResponse. In addition, your class must implement the IWebRequestCreate interface.
Example
The following example shows how to create a WebRequest instance and return the response.
// Initialize the WebRequest.
WebRequest myRequest = WebRequest.Create("http://www.contoso.com");

// Return the response. 
WebResponse myResponse = myRequest.GetResponse();

// Code to use the WebResponse goes here.

// Close the response to free resources.
myResponse.Close();


    
See also:
System.Net Namespace See also:
MSDN: requestingdata | MSDN: programmingpluggableprotocols | HttpWebRequest

System.Net.WebRequest Member List:

Public Properties
ConnectionGroupName Read-write

When overridden in a descendant class, gets or sets the name of the connection group for the request.
ContentLength Read-write

When overridden in a descendant class, gets or sets the content length of the request data being sent.
ContentType Read-write

When overridden in a descendant class, gets or sets the content type of the request data being sent.
Credentials Read-write

When overridden in a descendant class, gets or sets the network credentials used for authenticating the request with the Internet resource.
Headers Read-write

When overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.
Method Read-write

When overridden in a descendant class, gets or sets the protocol method to use in this request.
PreAuthenticate Read-write

When overridden in a descendant class, indicates whether to preauthenticate the request.
Proxy Read-write

When overridden in a descendant class, gets or sets the network proxy to use to access this Internet resource.
RequestUri Read-only

When overridden in a descendant class, gets the URI of the Internet resource associated with the request.
Timeout Read-write

Gets or sets the length of time before the request times out.
Public Methods
Abort Cancels an asynchronous request to an Internet resource.
BeginGetRequestStream When overridden in a descendant class, provides an asynchronous version of the WebRequest.GetRequestStream method.
BeginGetResponse When overridden in a descendant class, begins an asynchronous request for an Internet resource.
Create Overloaded:
Create(string requestUriString)

Initializes a new WebRequest instance for the specified URI scheme.
Create Overloaded:
Create(Uri requestUri)

Initializes a new WebRequest instance for the specified URI scheme.
CreateDefault Initializes a new WebRequest instance for the specified URI scheme.
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
EndGetRequestStream When overridden in a descendant class, returns a Stream for writing data to the Internet resource.
EndGetResponse When overridden in a descendant class, returns a WebResponse.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetRequestStream When overridden in a descendant class, returns a Stream for writing data to the Internet resource.
GetResponse When overridden in a descendant class, returns a response to an Internet request.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
RegisterPrefix Registers a WebRequest descendant for the specified URI.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the WebRequest class.
ctor #2 Overloaded:
.ctor(SerializationInfo serializationInfo, StreamingContext streamingContext)

Initializes a new instance of the WebRequest class from the specified instances of the SerializationInfo and StreamingContext classes.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.WebRequest Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the WebRequest class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
protected WebRequest();
Remarks
Use the WebRequest.Create method to initialize new WebRequest instances. Do not use the constructor.
Example
The following example shows how to create a WebRequest instance by calling the WebRequest.Create method on the WebRequest class.
WebRequest myRequest = WebRequest.Create("http://www.contoso.com");


    

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the WebRequest class from the specified instances of the SerializationInfo and StreamingContext classes.
C# Syntax:
protected WebRequest(
   SerializationInfo serializationInfo,
   StreamingContext streamingContext
);
Parameters:

serializationInfo

A SerializationInfo that contains the information required to serialize the new WebRequest instance.

streamingContext

A StreamingContext that indicates the source of the serialized stream associated with the new WebRequest instance.

Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the constructor, when the constructor is not overridden in a descendant class.
Remarks
When implemented by a descendant class, this constructor implements the ISerializable interface for the WebRequest descendant.
See also:
MSDN: serialization

Return to top


Property: ConnectionGroupName (read-write)
Summary
When overridden in a descendant class, gets or sets the name of the connection group for the request.
C# Syntax:
public virtual string ConnectionGroupName {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.ConnectionGroupName property associates specific requests within an application to one or more connection pools.

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

Notes to inheritors: The WebRequest.ConnectionGroupName property typically associates a group of requests that share a set of credentials with a connection to an Internet resource to avoid potential security failures.
See also:
HttpWebRequest.ConnectionGroupName | MSDN: connectiongrouping

Return to top


Property: ContentLength (read-write)
Summary
When overridden in a descendant class, gets or sets the content length of the request data being sent.
C# Syntax:
public virtual long ContentLength {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.ContentLength property contains the number of bytes of data sent to the Internet resource by the WebRequest instance.

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

Return to top


Property: ContentType (read-write)
Summary
When overridden in a descendant class, gets or sets the content type of the request data being sent.
C# Syntax:
public virtual string ContentType {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.ContentType property contains the media type of the request. This is typically the MIME encoding of the content.

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

Return to top


Property: Credentials (read-write)
Summary
When overridden in a descendant class, gets or sets the network credentials used for authenticating the request with the Internet resource.
C# Syntax:
public virtual ICredentials Credentials {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.Credentials property contains the authentication credentials required to access the Internet resource.

Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.
See also:
NetworkCredential | CredentialCache | HttpWebRequest.Credentials

Return to top


Property: Headers (read-write)
Summary
When overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.
C# Syntax:
public virtual WebHeaderCollection Headers {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.Headers property contains a WebHeaderCollection instance containing the header information to send to the Internet resource.

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

Return to top


Property: Method (read-write)
Summary
When overridden in a descendant class, gets or sets the protocol method to use in this request.
C# Syntax:
public virtual string Method {get; set;}
Exceptions
Exception Type Condition
NotSupportedException If the property is not overridden in a descendant class, any attempt is made to get or set the property.
Remarks
When overridden in a descendant class, the WebRequest.Method property contains the request method to use in this request.

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

Notes to inheritors: The WebRequest.Method property can contain any valid request method for the protocol implemented. The default value must provide a default request/response transaction that does not require protocol-specific properties to be set.
See also:
HttpWebRequest.Method

Return to top


Property: PreAuthenticate (read-write)
Summary
When overridden in a descendant class, indicates whether to preauthenticate the request.
C# Syntax:
public virtual bool PreAuthenticate {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.PreAuthenticate property indicates whether to send authentication information with the initial request. When WebRequest.PreAuthenticate is false, the WebRequest waits for an authentication challenge before sending authentication information.

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

Return to top


Property: Proxy (read-write)
Summary
When overridden in a descendant class, gets or sets the network proxy to use to access this Internet resource.
C# Syntax:
public virtual IWebProxy Proxy {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.Proxy property identifies the network proxy that the request uses to access the Internet resource. The request is made through the proxy server rather than directly to the Internet resource.

Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.
See also:
IWebProxy | WebProxy | HttpWebRequest.Proxy

Return to top


Property: RequestUri (read-only)
Summary
When overridden in a descendant class, gets the URI of the Internet resource associated with the request.
C# Syntax:
public virtual Uri RequestUri {get;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
When overridden in a descendant class, the WebRequest.RequestUri property contains the Uri instance that WebRequest.Create method uses to create the request.

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

Notes to inheritors: WebRequest.RequestUri must contain the original Uri instance passed to the WebRequest.Create method. If the protocol is able to redirect the request to a different URI to service the request, the descendant must provide a property to contain the URI that actually services the request
See also:
HttpWebRequest.RequestUri | HttpWebRequest.Address

Return to top


Property: Timeout (read-write)
Summary
Gets or sets the length of time before the request times out.
C# Syntax:
public virtual int Timeout {get; set;}
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.
Remarks
The WebRequest.Timeout property indicates the length of time, in milliseconds, until the request times out and throws a WebException. The WebRequest.Timeout property affects only synchronous requests made with the WebRequest.GetResponse method. To time out asynchronous requests, use the WebRequest.Abort method.

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

Notes to inheritors: Descendant classes signal a timeout by throwing a WebException with the WebException.Status field set to WebExceptionStatus.Timeout. When WebRequest.Timeout is set to Timeout.Infinite the descendant class does not time out.
See also:
HttpWebRequest.Timeout

Return to top


Method: Abort()
Summary
Cancels an asynchronous request to an Internet resource.
C# Syntax:
public virtual void Abort();
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.Abort method cancels asynchronous requests to Internet resources started with the WebRequest.BeginGetResponse method.

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

Return to top


Method: BeginGetRequestStream(
   AsyncCallback callback,
   object state
)
Summary
When overridden in a descendant class, provides an asynchronous version of the WebRequest.GetRequestStream method.
C# Syntax:
public virtual IAsyncResult BeginGetRequestStream(
   AsyncCallback callback,
   object state
);
Parameters:

callback

The AsyncCallback delegate.

state

An object containing state information for this asynchronous request.

Return Value:
An IAsyncResult that references the asynchronous request.
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.BeginGetRequestStream method starts an asynchronous request for a stream used to send data to an Internet resource. The callback method that implements the AsyncCallback delegate uses the WebRequest.EndGetRequestStream method to return the request stream.

Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.
See also:
WebRequest.EndGetRequestStream | MSDN: makingasynchronousrequests

Return to top


Method: BeginGetResponse(
   AsyncCallback callback,
   object state
)
Summary
When overridden in a descendant class, begins an asynchronous request for an Internet resource.
C# Syntax:
public virtual IAsyncResult BeginGetResponse(
   AsyncCallback callback,
   object state
);
Parameters:

callback

The AsyncCallback delegate.

state

An object containing state information for this asynchronous request.

Return Value:
An IAsyncResult that references the asynchronous request.
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.BeginGetResponse method starts an asynchronous request for a response. The callback method that implements the AsyncCallback delegate uses the WebRequest.EndGetResponse method to return the WebResponse from the Internet resource.

Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.
See also:
WebRequest.EndGetResponse | WebRequest.GetResponse | MSDN: makingasynchronousrequests

Return to top


Overloaded Method: Create(
   string requestUriString
)
Summary
Initializes a new WebRequest instance for the specified URI scheme.
C# Syntax:
public static WebRequest Create(
   string requestUriString
);
Parameters:

requestUriString

The URI that identifies the Internet resource.

Return Value:
A WebRequest descendant for the specific URI scheme.
Exceptions
Exception Type Condition
NotSupportedException The request scheme specified in requestUriString has not been registered.
ArgumentNullException requestUriString is null.
UriFormatException The URI specified in requestUriString is not a valid URI.
Remarks
The WebRequest.Create method returns a descendant of the WebRequest class determined at run time by the scheme of the URI in requestUriString. For example, when a URI beginning with http:// is passed in requestUriString, an HttpWebRequest instance is returned by WebRequest.Create. If a URI beginning with file:// is passed instead, the WebRequest.Create method will return a FileWebRequest instance.

The .NET Framework includes support for the http:// , https:// , and file:// URI schemes. Custom WebRequest descendants to handle other requests are registered with the WebRequest.RegisterPrefix method.

The WebRequest.Create method uses the requestUriString parameter to create a Uri instance that it passes to the new WebRequest.

See also:
MSDN: programmingpluggableprotocols

Return to top


Overloaded Method: Create(
   Uri requestUri
)
Summary
Initializes a new WebRequest instance for the specified URI scheme.
C# Syntax:
public static WebRequest Create(
   Uri requestUri
);
Parameters:

requestUri

A Uri containing the URI of the requested resource.

Return Value:
A WebRequest descendant for the specified URI scheme.
Exceptions
Exception Type Condition
NotSupportedException The request scheme specified in requestUri is not registered.
ArgumentNullException requestUri is null.
Remarks
The WebRequest.Create method returns a descendant of the WebRequest class determined at run time by the scheme of the URI in requestUri. For example, when a URI beginning with http:// is passed in requestUri, an HttpWebRequest instance is returned by WebRequest.Create. If a URI beginning with file:// is passed instead, the WebRequest.Create method will return a FileWebRequest instance.

The .NET Framework includes support for the http:// , https:// , and file:// URI schemes. Custom WebRequest descendants to handle other requests are registered with the WebRequest.RegisterPrefix method.

Return to top


Method: CreateDefault(
   Uri requestUri
)
Summary
Initializes a new WebRequest instance for the specified URI scheme.
C# Syntax:
public static WebRequest CreateDefault(
   Uri requestUri
);
Parameters:

requestUri

A Uri containing the URI of the requested resource.

Return Value:
A WebRequest descendant for the specified URI scheme.
Exceptions
Exception Type Condition
ArgumentNullException requestUri is null.
Remarks
The WebRequest.CreateDefault method returns a WebRequest descendant instance based on only the scheme portion of a URI.

For example, if you create a WebRequest descendant, Handler1, to handle requests to http://www.contoso.com/text/ and another named Handler2 to handle requests to http://www.contoso.com/code/, you can use the WebRequest.CreateDefault method to return a default WebRequest instance based on the URI scheme (in this case http).

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Method: EndGetRequestStream(
   IAsyncResult asyncResult
)
Summary
When overridden in a descendant class, returns a Stream for writing data to the Internet resource.
C# Syntax:
public virtual Stream EndGetRequestStream(
   IAsyncResult asyncResult
);
Parameters:

asyncResult

An IAsyncResult that references a pending request for a stream.

Return Value:
A Stream to write data to.
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.EndGetRequestStream method completes an asynchronous stream request that was started by the WebRequest.BeginGetRequestStream method.

Note To avoid timing issues with garbage collection, be sure to close the response stream by calling the Stream.Close method on the stream returned by WebResponse.GetResponseStream after calling WebRequest.EndGetResponse.

Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.
See also:
WebRequest.BeginGetRequestStream | MSDN: makingasynchronousrequests

Return to top


Method: EndGetResponse(
   IAsyncResult asyncResult
)
Summary
When overridden in a descendant class, returns a WebResponse.
C# Syntax:
public virtual WebResponse EndGetResponse(
   IAsyncResult asyncResult
);
Parameters:

asyncResult

An IAsyncResult that references a pending request for a response.

Return Value:
A WebResponse that contains a response to the Internet request.
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.EndGetResponse method completes an asynchronous request for an Internet resource that was started with the WebRequest.BeginGetResponse method.

Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.
See also:
WebRequest.BeginGetResponse | MSDN: makingasynchronousrequests

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~WebRequest();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Method: GetRequestStream()
Summary
When overridden in a descendant class, returns a Stream for writing data to the Internet resource.
C# Syntax:
public virtual Stream GetRequestStream();
Return Value:
A Stream for writing data to the Internet resource.
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.GetRequestStream method initiates a request to send data to the Internet resource and returns a Stream instance for sending data to the Internet resource.

The WebRequest.GetRequestStream method provides synchronous access to the Stream. For asynchronous access, use the WebRequest.BeginGetRequestStream and WebRequest.EndGetRequestStream methods.



Note The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.
See also:
MSDN: usingstreamsonnetwork | WebRequest.BeginGetRequestStream

Return to top


Method: GetResponse()
Summary
When overridden in a descendant class, returns a response to an Internet request.
C# Syntax:
public virtual WebResponse GetResponse();
Return Value:
A WebResponse containing the response to the Internet request.
Exceptions
Exception Type Condition
NotSupportedException Any attempt is made to access the method, when the method is not overridden in a descendant class.
Remarks
The WebRequest.GetResponse method sends a request to an Internet resource and returns a WebResponse instance. If the request has already been initiated by a call to WebRequest.GetRequestStream, the WebRequest.GetResponse method completes the request and returns any response.

The WebRequest.GetResponse method provides synchronous access to the WebResponse. For asynchronous access, use the WebRequest.BeginGetResponse and WebRequest.EndGetResponse methods.



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

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: RegisterPrefix(
   string prefix,
   IWebRequestCreate creator
)
Summary
Registers a WebRequest descendant for the specified URI.
C# Syntax:
public static bool RegisterPrefix(
   string prefix,
   IWebRequestCreate creator
);
Parameters:

prefix

The URI prefix that the WebRequest descendant services.

creator

The create method that the WebRequest calls to create the WebRequest descendant.

Return Value:
true if registration is successful; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException prefix is null

-or-

creator is null.

Remarks
The WebRequest.RegisterPrefix method registers WebRequest descendants to service requests. WebRequest descendants are typically registered to handle a specific protocol, such HTTP or FTP, but can be registered to handle a request to a specific server or path on a server.

Duplicate prefixes are not allowed. WebRequest.RegisterPrefix returns false if an attempt is made to register a duplicate prefix.



Note The HttpWebRequest class is registered to service requests for HTTP and HTTPS schemes by default. Attempts to register a different WebRequest descendant for these schemes will fail.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.