HttpWebResponse.Close Yöntem

Tanım

Yanıt akışını kapatır.

public:
 override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()

Özel durumlar

Yalnızca .NET Core: Bu HttpWebResponse nesne atıldı.

Örnekler

Aşağıdaki örnekte bir öğesinin nasıl kapatılmaya devam olduğu gösterilmektedir HttpWebResponse.

// 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" );
// 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");
' 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")

Açıklamalar

Close yöntemi yanıt akışını kapatır ve diğer istekler tarafından yeniden kullanılmak üzere kaynak bağlantısını serbest bırakır.

yöntemine yapılan çağrıdan HttpWebResponse sonra nesnenin hiçbir özelliğine Close erişmemelisiniz. .NET Core'da bir ObjectDisposedException oluşturulur.

Akışı kapatmak ve bağlantıyı yeniden kullanmak üzere serbest bırakmak için veya HttpWebResponse.Close yöntemini çağırmanız Stream.Close gerekir. hem HttpWebResponse.Closehem de Stream.Close çağrısı yapmak gerekli değildir, ancak bunu yapmak hataya neden olmaz. Akışın kapatılamaması uygulamanızın bağlantılarının kapanmasına neden olabilir.

Not

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için .NET Framework ağ izleme bölümüne bakın.

Şunlara uygulanır