다음을 통해 공유


FileWebResponse.Close 메서드

정의

응답 스트림을 닫습니다.

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

예제

다음 예제에서는 메서드를 Close 사용하여 응답 스트림을 닫습니다.

void GetPage( String^ url )
{
   try
   {
      Uri^ fileUrl = gcnew Uri( String::Concat( "file://", url ) );
      // Create a FileWebrequest with the specified Uri.
      FileWebRequest^ myFileWebRequest = dynamic_cast<FileWebRequest^>(WebRequest::Create( fileUrl ));
      // Send the 'fileWebRequest' and wait for response.
      FileWebResponse^ myFileWebResponse = dynamic_cast<FileWebResponse^>(myFileWebRequest->GetResponse());
      // Process the response here.
      Console::WriteLine( "\nResponse Received::Trying to Close the response stream.." );
      // Release resources of response Object*.
      myFileWebResponse->Close();
      Console::WriteLine( "\nResponse Stream successfully closed." );
   }
   catch ( WebException^ e ) 
   {
      Console::WriteLine( "\r\nWebException thrown. The Reason for failure is : {0}", e->Status );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "\nThe following Exception was raised : {0}", e->Message );
   }
}
public static void GetPage(String url)
 {
     try
     {
         Uri fileUrl = new Uri("file://"+url);
         // Create a FileWebrequest with the specified Uri.
         FileWebRequest myFileWebRequest = (FileWebRequest)WebRequest.Create(fileUrl);
         // Send the 'fileWebRequest' and wait for response.
         FileWebResponse myFileWebResponse = (FileWebResponse)myFileWebRequest.GetResponse();
         // Process the response here.
         Console.WriteLine("\nResponse Received.Trying to Close the response stream..");
         // Release resources of response object.
         myFileWebResponse.Close();
      Console.WriteLine("\nResponse Stream successfully closed.");
      }
     catch(WebException e)
      {
        Console.WriteLine("\r\nWebException thrown. The Reason for failure is : {0}",e.Status);
    }
     catch(Exception e)
    {
        Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
     }
}
Public Shared Sub GetPage(url As [String])
    Try
        Dim fileUrl As New Uri("file://" + url)
        ' Create a FileWebrequest with the specified Uri. 
        Dim myFileWebRequest As FileWebRequest = CType(WebRequest.Create(fileUrl), FileWebRequest)
        ' Send the 'fileWebRequest' and wait for response.
        Dim myFileWebResponse As FileWebResponse = CType(myFileWebRequest.GetResponse(), FileWebResponse)
        ' Process the response here
        Console.WriteLine(ControlChars.Cr + "Response Received.Trying to Close the response stream..")
        ' The method call to release resources of response object.
        myFileWebResponse.Close()
        Console.WriteLine(ControlChars.Cr + "Response Stream successfully closed")
    Catch e As WebException
        Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "The Reason for failure is : {0}", e.Status)
    Catch e As Exception
        Console.WriteLine(ControlChars.Cr + "The following exception was raised : {0}", e.Message)
    End Try

설명

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

참고

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

적용 대상