HttpWebResponse.LastModified 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取最后一次修改响应内容的日期和时间。
public:
property DateTime LastModified { DateTime get(); };
public DateTime LastModified { get; }
member this.LastModified : DateTime
Public ReadOnly Property LastModified As DateTime
属性值
DateTime,包含修改响应内容的日期和时间。
例外
已释放当前实例。
示例
此示例创建 HttpWebRequest 并查询响应。 然后,此示例检查请求的实体是否在今天的任何时间被修改过。
Uri^ myUri = gcnew 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();
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();
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()
注解
属性 LastModified 包含随响应一起收到的 Last-Modified 标头的值。 日期和时间假定为本地时间。