HttpClient HttpResponseMessage LastModified 文件日期

HttpClient HttpResponseMessage LastModified date of file

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

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

response.Headers.Date.Value

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

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

response.Headers[HttpResponseHeader.LastModified]

将 return 上次更改文件的日期,例如2 种不同的方法 return 不同的日期,HttpWebResponse 给出的日期是 2017 年 1 月 12 日,而 HttpResponseMessage 给出的日期是 2017 年 3 月 30 日。

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

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

"The Last-Modified HTTP header is treated as part of the HTTP response content rather than the HTTP response itself,"

我能够通过访问响应内容 headers 而不是 headers 本身

来提取 LastModified 日期
DateTime lastModified = result.Content.Headers.LastModified;