Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpWebResponse Class

Provides an HTTP-specific implementation of the WebResponse class.

For a list of all members of this type, see HttpWebResponse Members.

System.Object
   System.MarshalByRefObject
      System.Net.WebResponse
         System.Net.HttpWebResponse

[Visual Basic]
<Serializable>
Public Class HttpWebResponse
   Inherits WebResponse
[C#]
[Serializable]
public class HttpWebResponse : WebResponse
[C++]
[Serializable]
public __gc class HttpWebResponse : public WebResponse
[JScript]
public
   Serializable
class HttpWebResponse extends WebResponse

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.

Remarks

This class contains support for HTTP-specific uses of the properties and methods of the WebResponse class. The HttpWebResponse class is used to build HTTP stand-alone client applications which send HTTP requests and receive HTTP responses.

Note   Do not confuse HttpWebResponse with the HttpResponse which is used in ASP.NET applications and whose methods and properties are exposed through the ASP.NET's intrinsic HttpResponse object.

You should never directly create an instance of the HttpWebResponse class. Instead, use the instance returned by a call to HttpWebRequest.GetResponse. You must call either the Stream.Close or the HttpWebResponse.Close method to close the response and release the connection for reuse. It is not necessary to call both Stream.Close and HttpWebResponse.Close, but doing so does not cause an error.

Common header information returned from the Internet resource is exposed as properties of the class. See the following table for a complete list. Other headers can be read from the Headers property as name/value pairs.

The following table shows the common HTTP headers that are available through properties of the HttpWebResponse class.

Header Property
Content-Encoding ContentEncoding
Content-Length ContentLength
Content-Type ContentType
Last-Modified LastModified
Server Server

The contents of the response from the Internet resource are returned as a Stream by calling the GetResponseStream method.

Example

The following example returns an HttpWebResponse from an HttpWebRequest:

[Visual Basic] 
Dim HttpWReq As HttpWebRequest = _
   CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
       
Dim HttpWResp As HttpWebResponse = _
   CType(HttpWReq.GetResponse(), HttpWebResponse)
' Insert code that uses the response object.
HttpWResp.Close()

[C#] 
HttpWebRequest HttpWReq = 
(HttpWebRequest)WebRequest.Create("http://www.contoso.com");

HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
HttpWResp.Close();

[C++] 
HttpWebRequest* HttpWReq = 
dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"http://www.contoso.com"));

HttpWebResponse* HttpWResp = dynamic_cast<HttpWebResponse*>(HttpWReq->GetResponse());
// Insert code that uses the response object.
HttpWResp->Close();

[JScript] 
var httpWReq : HttpWebRequest = HttpWebRequest(WebRequest.Create("http://www.contoso.com"))
       
var httpWResp : HttpWebResponse = HttpWebResponse(httpWReq.GetResponse())
// Insert code to use response object.
httpWResp.Close()

Requirements

Namespace: System.Net

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

HttpWebResponse Members | System.Net Namespace | WebResponse

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft