[英]HttpClient HttpResponseMessage LastModified date of file
I am using the C# HttpClient to simulate a request to download a CSV file from a server. 我正在使用C#HttpClient来模拟从服务器下载CSV文件的请求。 I need to check the LastModified dateof the file against the LastModified date of the previous file I downloaded to check if the file has changed.
我需要根据我下载的上一个文件的LastModified日期检查文件的LastModified日期,以检查文件是否已更改。
HttpClient gets a HttpResponseMessage when I make the request, but every time I check 我发出请求时,HttpClient会获取HttpResponseMessage,但每次检查时都会
response.Headers.Date.Value
I get the current Date/Time that the request was made. 我得到了请求的当前日期/时间。 I understand that if the page I'm requesting the file from is generated by a DB or by some other dynamic method, the LastModified value will be the time that the request was made.
我理解,如果我请求文件的页面是由DB或其他动态方法生成的,则LastModified值将是请求发出的时间。
However, I have tried the same process using the older HttpWebRequest/Response and I found that 但是,我使用较旧的HttpWebRequest / Response尝试了相同的过程,我发现了
response.Headers[HttpResponseHeader.LastModified]
Will return the date that the file was last changed, eg the 2 different methods return different dates, HttpWebResponse gives a date of 1/12/2017, and HttpResponseMessage gives a date of 3/30/2017. 将返回文件上次更改的日期,例如,2种不同的方法返回不同的日期,HttpWebResponse给出日期为1/12/2017,HttpResponseMessage给出日期为2017年3月30日。
How can I get the file change date using HttpWebResponse? 如何使用HttpWebResponse获取文件更改日期?
From https://social.msdn.microsoft.com/Forums/windowsapps/en-US/c830971a-e60f-4759-ba2a-42638b0afad0/uwp-lastmodifiedheader-invalid?forum=wpdevelop 来自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," “Last-Modified HTTP标头被视为HTTP响应内容的一部分,而不是HTTP响应本身,”
I was able to pull the LastModified date by accessing the Content of the response headers, not the headers themselves 我能够通过访问响应标头的内容而不是标头本身来提取LastModified日期
DateTime lastModified = result.Content.Headers.LastModified;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.