简体   繁体   English

HttpClient HttpResponseMessage LastModified文件的日期

[英]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.

相关问题 HttpClient HttpResponseMessage地址/ URI - HttpClient HttpResponseMessage Address / URI HttpClient:使用HttpResponseMessage.Content.ReadAsStreamAsync()时限制响应(下载的文件)大小 - HttpClient: limit response (downloaded file) size while using HttpResponseMessage.Content.ReadAsStreamAsync() 使用HttpClient和HttpResponseMessage的带有两个字符串的PostAsync - PostAsync with two strings using HttpClient and HttpResponseMessage Output 从 HttpClient HttpResponseMessage 到控制台的所有标头 - Output all headers from HttpClient HttpResponseMessage to console 异步调用HttpClient以通过Ajax获取HttpResponseMessage - Calling HttpClient asynchronously to get the HttpResponseMessage via ajax 使用HttpClient发布并读取HttpResponseMessage状态 - Post using HttpClient & Read HttpResponseMessage status 如何在C#中获取HttpWebResponse的LastModified日期? - How to get LastModified date of the HttpWebResponse in c#? 将LastModified日期保存在用户详细信息旁边 - Saving LastModified Date alongside User details 如何添加到HttpResponseMessage文件和字符串 - how to add to HttpResponseMessage file and string 使用HttpClient时HttpResponseMessage缺少标头,但提琴手找到了 - HttpResponseMessage missing headers while using HttpClient but fiddler finds it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM