我正在尝试获取 URL 的 LastModified 日期,但它总是返回今天(当前日期)。我检查了许多 URL,但结果是一样的。我尝试了 winform 和 web 应用程序。
这是我的代码。请帮我修复它。
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();
}