HttpWebResponse.LastModified プロパティ
応答の内容が最後に変更された日付と時刻を取得します。
Public ReadOnly Property LastModified As DateTime
[C#]
public DateTime LastModified {get;}
[C++]
public: __property DateTime get_LastModified();
[JScript]
public function get LastModified() : DateTime;
プロパティ値
応答の内容が変更された日付と時刻を格納する DateTime 。
例外
例外の種類 | 条件 |
---|---|
ObjectDisposedException | 現在のインスタンスは破棄されています。 |
解説
LastModified プロパティは、応答で受信される Last-Modified ヘッダーの値を格納します。日付と時刻は、現地時刻であると見なされます。
使用例
[Visual Basic, C#, C++] この例では、 HttpWebRequest を作成し、応答を問い合わせます。この例では、次に、要求したエンティティが今日の任意の時刻に変更されたかどうかを確認します。
Dim myUri As New Uri(url)
' Creates an HttpWebRequest for the specified URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(myUri), HttpWebRequest)
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "Request succeeded and the requested information is in the response , Description : {0}", myHttpWebResponse.StatusDescription)
End If
Dim today As DateTime = DateTime.Now
' Uses the LastModified property to compare with today's date.
If DateTime.Compare(today, myHttpWebResponse.LastModified) = 0 Then
Console.WriteLine(ControlChars.Cr + "The requested URI entity was modified today")
Else
If DateTime.Compare(today, myHttpWebResponse.LastModified) = 1 Then
Console.WriteLine(ControlChars.Cr + "The requested Uri was last modified on:{0}", myHttpWebResponse.LastModified)
End If
End If
' Releases the resources of the response.
myHttpWebResponse.Close()
[C#]
Uri myUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
Console.WriteLine("\r\nRequest succeeded and the requested information is in the response , Description : {0}",
myHttpWebResponse.StatusDescription);
DateTime today = DateTime.Now;
// Uses the LastModified property to compare with today's date.
if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 0)
Console.WriteLine("\nThe requested URI entity was modified today");
else
if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 1)
Console.WriteLine("\nThe requested URI was last modified on:{0}",
myHttpWebResponse.LastModified);
// Releases the resources of the response.
myHttpWebResponse.Close();
[C++]
Uri* myUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest* myHttpWebRequest =
dynamic_cast<HttpWebRequest*>(WebRequest::Create(myUri));
HttpWebResponse* myHttpWebResponse =
dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
if (myHttpWebResponse->StatusCode == HttpStatusCode::OK)
Console::WriteLine(S"\r\nRequest succeeded and the requested information is in the response , Description : {0}",
myHttpWebResponse->StatusDescription);
DateTime today = DateTime::Now;
// Uses the LastModified property to compare with today's date.
if (DateTime::Compare(today, myHttpWebResponse->LastModified) == 0)
Console::WriteLine(S"\nThe requested URI entity was modified today");
else
if (DateTime::Compare(today, myHttpWebResponse->LastModified) == 1)
Console::WriteLine(S"\nThe requested URI was last modified on: {0}",
__box(myHttpWebResponse->LastModified));
// Releases the resources of the response.
myHttpWebResponse->Close();
[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 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard