开发者

HTTP Last Updated

I want to write something in .NET that will be given a URI and return the date/time when it was 开发者_如何学Pythonlast updated. Is there something easy I can check? I assume there is a last updated property I can hook into? Is this reliable? How does it work with timezones?

Thanks


There is an HTTP-Last-Modified header, which should suit your purposes. A properly configured server should return this in UTC.

Something like this might do:

        using (WebClient client = new WebClient())
        {
            client.OpenRead("http://www.stackoverflow.com");
            string lastModified = client.ResponseHeaders["Last-Modified"];
            DateTime dateLastModified = DateTime.Parse(lastModified);
            Console.WriteLine(string.Format("Last updated on {0:dd-MMM-yyyy HH:mm}", dateLastModified));
        }

which (right now) returns

Last updated on 03-Oct-2011 12:03

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜