FileWebResponse.Close メソッド
応答ストリームを閉じます。
Overrides Public Sub Close()
[C#]
public override void Close();
[C++]
public: void Close();
[JScript]
public override function Close();
解説
Close メソッドは、 FileWebResponse によって使用されたリソースをクリーンアップし、 Stream.Close メソッドを呼び出して、応答ストリームを閉じます。
メモ システム リソースの不足を防ぐために、応答ストリームを閉じる必要があります。 Stream.Close または Close のいずれかを呼び出して、応答ストリームを閉じることができます。
使用例
[Visual Basic, C#, C++] Close メソッドを使用して、応答ストリームを閉じる例を次に示します。
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
[C#]
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);
}
}
[C++]
void GetPage(String* url) {
try {
Uri* fileUrl = new Uri(String::Concat(S"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(S"\nResponse Received::Trying to Close the response stream..");
// Release resources of response Object*.
myFileWebResponse->Close();
Console::WriteLine(S"\nResponse Stream successfully closed.");
} catch (WebException* e) {
Console::WriteLine(S"\r\nWebException thrown.The Reason for failure is : {0}", __box( e->Status));
} catch (Exception* e) {
Console::WriteLine(S"\nThe following Exception was raised : {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ