我想喲取URL的LastModified日期,但它總是返回今天(當前日期)。我檢查了很多網址,但結果相同。我嘗試了winform和web應用程序。URL的LastModified日期
這是我的代碼。請幫我解決它。
Uri myUri = new Uri(TextBox1.Text);
// 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();
}
http://stackoverflow.com/questions/6338839/how-to-get-last-modified-date-of-the-webpage-in-c –
您可以通過使用Fiddler來驗證此代碼是否正常工作(或您選擇的調試代理)爲自己查看服務器的「上次修改」標題。 – David