8

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, e.g. 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?

1 Answer 1

20

From 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,"

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.