gpt4 book ai didi

c# - HttpClient HttpResponseMessage LastModified 文件日期

转载 作者:太空狗 更新时间:2023-10-29 22:21:30 25 4
gpt4 key购买 nike

我正在使用 C# HttpClient 来模拟从服务器下载 CSV 文件的请求。我需要检查文件的 LastModified 日期与我下载的上一个文件的 LastModified 日期,以检查文件是否已更改。

当我发出请求时,HttpClient 得到一个 HttpResponseMessage,但每次我检查

response.Headers.Date.Value

我得到发出请求的当前日期/时间。我知道,如果我从中请求文件的页面是由数据库或其他动态方法生成的,则 LastModified 值将是发出请求的时间。

但是,我使用旧的 HttpWebRequest/Response 尝试了相同的过程,我发现

response.Headers[HttpResponseHeader.LastModified]

将返回文件最后更改的日期,例如2 种不同的方法返回不同的日期,HttpWebResponse 给出的日期是 1/12/2017,而 HttpResponseMessage 给出的日期是 3/30/2017。

如何使用 HttpWebResponse 获取文件更改日期?

最佳答案

来自 https://social.msdn.microsoft.com/Forums/windowsapps/en-US/c830971a-e60f-4759-ba2a-42638b0afad0/uwp-lastmodifiedheader-invalid?forum=wpdevelop

“Last-Modified HTTP header 被视为 HTTP 响应内容的一部分,而不是 HTTP 响应本身,”

我能够通过访问响应 header 的内容而不是 header 本身来提取 LastModified 日期

DateTime lastModified = result.Content.Headers.LastModified;

关于c# - HttpClient HttpResponseMessage LastModified 文件日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43125666/

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