WebResponse.Close 메서드

정의

서브클래스에서 재정의될 때, 응답 스트림을 닫습니다.

public:
 virtual void Close();
public virtual void Close ();
abstract member Close : unit -> unit
override this.Close : unit -> unit
Public Overridable Sub Close ()

예외

메서드가 서브클래스에서 재정의되지 않았는데 메서드에 액세스하려 할 경우

예제

다음 예제에서는 메서드를 사용하여 를 Close 닫습니다 WebResponse.

// Create a 'WebRequest' object with the specified url.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );
// Send the 'WebRequest' and wait for response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Process the response here.
Console::WriteLine( "\nResponse Received::Trying to Close the response stream.." );
// Release resources of response Object*.
myWebResponse->Close();
Console::WriteLine( "\nResponse Stream successfully closed" );
// Create a 'WebRequest' object with the specified url. 	
WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com"); 
// Send the 'WebRequest' and wait for response.	
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Process the response here.
Console.WriteLine("\nResponse Received.Trying to Close the response stream..");
// Release resources of response object.
myWebResponse.Close();
Console.WriteLine("\nResponse Stream successfully closed");
' Create a 'WebRequest' object with the specified url 	
Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")
' Send the 'WebRequest' and wait for response.	
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

'  Process the response here
Console.WriteLine(ControlChars.Cr + "Response Received.Trying to Close the response stream..")
' Release resources of response object
myWebResponse.Close()
Console.WriteLine(ControlChars.Cr + "Response Stream successfully closed")

설명

메서드는 Close 에서 사용하는 WebResponse 리소스를 정리하고 메서드를 호출하여 기본 스트림을 Stream.Close 닫습니다.

참고

시스템 리소스가 부족하지 않도록 응답을 닫아야 합니다. 또는 를 호출 Stream.CloseClose하여 응답 스트림을 닫을 수 있습니다.

참고

클래스는 WebResponse 클래스입니다 abstract . 런타임에 인스턴스의 WebResponse 실제 동작은 에서 반환 WebRequest.GetResponse된 하위 클래스에 의해 결정됩니다. 기본값 및 예외에 대한 자세한 내용은 및 FileWebResponse와 같은 HttpWebResponse 하위 클래스에 대한 설명서를 참조하세요.

적용 대상

추가 정보