I am using the C# HttpClient to simulate a request to download a CSV file from a server. 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.
HttpClient gets a HttpResponseMessage when I make the request, but every time I check
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.
However, I have tried the same process using the older HttpWebRequest/Response and I found that
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.
How can I get the file change date using HttpWebResponse?
"The Last-Modified HTTP header is treated as part of the HTTP response content rather than the HTTP response itself,"
I was able to pull the LastModified date by accessing the Content of the response headers, not the headers themselves
DateTime lastModified = result.Content.Headers.LastModified;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.