Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
System.Net
WebResponse Class

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
WebResponse Class

Provides a response from a Uniform Resource Identifier (URI). This is an abstract class.

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

Visual Basic (Declaration)
<SerializableAttribute> _
Public MustInherit Class WebResponse
    Inherits MarshalByRefObject
    Implements ISerializable, IDisposable
Visual Basic (Usage)
Dim instance As WebResponse
C#
[SerializableAttribute] 
public abstract class WebResponse : MarshalByRefObject, ISerializable, IDisposable
C++
[SerializableAttribute] 
public ref class WebResponse abstract : public MarshalByRefObject, ISerializable, IDisposable
J#
/** @attribute SerializableAttribute() */ 
public abstract class WebResponse extends MarshalByRefObject implements ISerializable, IDisposable
JScript
SerializableAttribute 
public abstract class WebResponse extends MarshalByRefObject implements ISerializable, IDisposable

The WebResponse class is the abstract base class from which protocol-specific response classes are derived. Applications can participate in request and 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.

Client applications do not create WebResponse objects directly; they are created by calling the GetResponse method on a WebRequest instance.

Notes to Inheritors When you inherit from WebResponse, you must override the following members: ContentLength, ContentType, GetResponseStream, ResponseUri, and Headers.

The following example creates a WebResponse instance from a WebRequest.

Visual Basic
' Initialize the WebRequest.
Dim myRequest As WebRequest = WebRequest.Create("http://www.contoso.com")

' Return the response. 
Dim myResponse As WebResponse = myRequest.GetResponse()

' Code to use the WebResponse goes here.
' Close the response to free resources.
myResponse.Close()

C#
// 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();

C++
// 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();
J#
// 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.Object
   System.MarshalByRefObject
    System.Net.WebResponse
       System.Net.FileWebResponse
       System.Net.FtpWebResponse
       System.Net.HttpWebResponse
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker