Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

HttpWebResponse.Close Method

Closes the response stream.

[Visual Basic]
Overrides Public Sub Close()
[C#]
public override void Close();
[C++]
public: void Close();
[JScript]
public override function Close();

Remarks

The Close method closes the response stream and releases the connection to the Internet resource for reuse by other requests.

Note   You must call either the Stream.Close or the HttpWebResponse.Close method to close the stream 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. Failure to close the stream will cause your application to run out of connections.

Example

[Visual Basic, C#, C++] The following example demonstrates how to close HttpWebResponse.

[Visual Basic] 
' Creates an HttpWebRequest for the specified URL. 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
' Sends the HttpWebRequest and waits for a response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Console.WriteLine("Response Received.Trying to Close the response stream..")
' Releases the resources of the response.
myHttpWebResponse.Close()
Console.WriteLine("Response Stream successfully closed")

[C#] 
// Creates an HttpWebRequest for the specified URL. 
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
    // Sends the HttpWebRequest and waits for a response.
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
    Console.WriteLine("\nResponse Received.Trying to Close the response stream..");
    // Releases the resources of the response.
    myHttpWebResponse.Close(); 
    Console.WriteLine("\nResponse Stream successfully closed");

[C++] 
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(url));
// Sends the HttpWebRequest and waits for a response.
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
Console::WriteLine(S"\nResponse Received::Trying to Close the response stream..");
// Releases the resources of the response.
myHttpWebResponse->Close();
Console::WriteLine(S"\nResponse Stream successfully closed");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

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, Common Language Infrastructure (CLI) Standard

See Also

HttpWebResponse Class | HttpWebResponse Members | System.Net Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.