FileWebResponse.Close 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
關閉回應資料流。
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