public abstract class WebResponse : MarshalByRefObject, IDisposable
Object
MarshalByRefObject
WebResponseThis type implements IDisposable.
System
Networking
Represents a response received from a Uniform Resource Identifier (URI).
WebResponse is the base class from which protocol-specific response classes, such as HttpWebResponse , are derived.Classes that derive from WebResponse are required to override the following members in the WebResponse class:
[Note: Applications can participate in request/response transactions in a protocol-agnostic manner using instances of the WebResponse class while protocol-specific classes derived from WebResponse carry out the details of the request.
- System.Net.WebResponse.ContentLength: Gets or sets the content length of the data being received.
- System.Net.WebResponse.ContentType: Gets or sets the media type of the data being received.
- System.Net.WebResponse.GetResponseStream: Returns a Stream that contains data from the current host.
- System.Net.WebResponse.ResponseUri: Gets a Uri containing the URI of the resource associated with the current instance.
- System.Net.WebResponse.Headers: Gets or sets the collection of header name/value pairs associated with the current instance.
Applications do not create WebResponse objects directly; they are created by calling System.Net.WebRequest.GetResponse .
]
The following example creates a WebResponse instance from a WebRequest .
using System; using System.Net; public class WebResponseExample { public static void Main() { // 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(); } }
System.Net Namespace
WebResponse Constructors
WebResponse Methods
WebResponse.Close Method
WebResponse.GetResponseStream Method
WebResponse.System.IDisposable.Dispose Method
WebResponse Properties
WebResponse.ContentLength Property
WebResponse.ContentType Property
WebResponse.Headers Property
WebResponse.ResponseUri Property
protected WebResponse();
Constructs a new instance of the WebResponse class.
This constructor is called only by classes that derive from WebResponse.[Note: To obtain a WebResponse instance, use the System.Net.WebRequest.GetResponse method; do not use this constructor.]
System.Net.WebResponse Class, System.Net Namespace
public virtual void Close();
Closes the response stream.
Exception Type Condition NotSupportedException This method is not implemented in the derived class.
[Behaviors: This method is required to free the connection used by the Stream returned by a call to System.Net.WebResponse.GetResponseStream .]
[Default: The WebResponse class is abstract and does not provide an implementation for this method. This method throws NotSupportedException.]
[Overrides: This method is required to be overridden in derived classes to close the response stream and free resources allocated by the current instance.]
[Usage: Use this method or System.IO.Stream.Close to clean up the resources used by a WebResponse .]
System.Net.WebResponse Class, System.Net Namespace
public virtual Stream GetResponseStream();
Returns a Stream that contains data from the current host.
A Stream for reading data from the current host.
Exception Type Condition NotSupportedException This method is not implemented in the derived class.
[Behaviors: This method is required to return a Stream from the host specified by the System.Net.WebResponse.ResponseUri property of the current instance.]
[Default: This method throws NotSupportedException.]
[Overrides: This method is required to be overridden by classes that inherit from WebResponse.]
[Usage: Use this method to open a connection to the current host. To close the stream when it is no longer needed, in order to prevent the exhaustion of system resources, invoke either the System.IO.Stream.Close or System.Net.WebResponse.Close methods.]
System.Net.WebResponse Class, System.Net Namespace
void IDisposable.Dispose();
Implemented to support the IDisposable interface. [Note: For more information, see System.IDisposable.Dispose.]
System.Net.WebResponse Class, System.Net Namespace
public virtual long ContentLength { get; set; }
Gets or sets the content length of the data received from the server.
A Int64 containing the number of bytes returned from the resource.
Exception Type Condition NotSupportedException This property is not implemented in the derived class.
[Behaviors: This property contains the number of bytes of data in the response to the request associated with the current instance. For request methods that contain header information, the System.Net.WebResponse.ContentLength does not include the length of the header information. The value of this property is set by the Content-Length header received in the response.]
[Default: The WebResponse class is abstract and does not provide an implementation for this property. This property throws NotSupportedException.]
[Overrides: This property is required to be overridden by classes that inherit from WebResponse to set the content length as appropriate for the derived class. ]
[Usage: Use this property to determine the number of bytes in the response.]
System.Net.WebResponse Class, System.Net Namespace
public virtual string ContentType { get; set; }
Gets or sets the media type of the data received.
A String that contains the media type of the response data.
Exception Type Condition NotSupportedException This property is not implemented in the derived class.
[Note: The media type is typically the MIME encoding of the content.]
[Behaviors: As described above.]
[Default: The WebResponse class is abstract and does not provide an implementation for this property. This property throws NotSupportedException.]
[Overrides: This property is required to be overridden by classes that inherit from WebResponse.]
[Usage: Use this property to get the media type of the response.]
System.Net.WebResponse Class, System.Net Namespace
public virtual WebHeaderCollection Headers { get; }
Gets the collection of header name/value pairs associated with the current instance.
A WebHeaderCollection containing the header name/value pairs associated with the current instance.
Exception Type Condition NotSupportedException This property is not implemented in the derived class.
This property contains a WebHeaderCollection instance containing the header information returned in the response from the resource.[Behaviors: This property is read-only.]
[Default: The WebResponse class is abstract and does not provide an implementation for this property. This property throws NotSupportedException.]
[Overrides: This property is required to be overridden by classes that inherit from WebResponse.]
[Usage: Use this property to retrieve the header information received with the response.]
System.Net.WebResponse Class, System.Net Namespace
public virtual Uri ResponseUri { get; }
Gets the URI of the resource associated with the current instance.
A Uri containing the URI of the resource associated with the current response.
Exception Type Condition NotSupportedException This property is not implemented in the derived class.
[Behaviors: This property is read-only.This property returns the URI that provided the response information in the current instance. [Note: If the method protocol used in the associated WebRequest permits redirection, the value of this property might differ from the System.Net.WebRequest.RequestUri property of the request.]
]
[Default: The WebResponse class is abstract and does not provide an implementation for this property. This property throws NotSupportedException .]
[Overrides: This property is required to be overridden by classes that inherit from WebResponse.]
[Usage: Use this property to determine the URI that originated the response.]
System.Net.WebResponse Class, System.Net Namespace