gpt4 book ai didi

c# - URL 的最后修改日期

转载 作者:太空宇宙 更新时间:2023-11-03 11:14:19 24 4
gpt4 key购买 nike

我正在尝试获取 url 的 LastModified 日期,但它总是返回今天(当前日期)。我检查了很多网址,但结果是一样的。我尝试了 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();
}

最佳答案

根据 this explanation :

If your website is using plain HTML files, the "Last-Modified" is just the time stamp of the HTML file. If you have, however, dynamic pages that fetch data from a database for example, things are a bit more complex. The server does not know how you are generating your data or how the data can be changed from the last time it was loaded.

因此,对于目前大多数 Web 服务器而言,“最后修改”日期将是页面呈现的日期,因为 A) 配置服务器以了解数据是否已更改是许多人赢得的额外工作不这样做,并且 B) 通常数据已经改变。

关于c# - URL 的最后修改日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13144529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com