Reputation: 1133
I am using C# ASP.NET 4. So far as I can tell, the HttpWebRequest object is not using the format defined by RFC2616 for the Date header. Is there a way to tell a DateTime class how I want the string representation to be formatted, or is there a way to set the Date header to a string? What I am seeing is: "11/5/2011 1:55:15 PM". The correct DateTime format string for HTTP requests is: @"ddd, dd MMM yyyy HH:mm:ss G\MT".
I have tried this, It threw and error.
Request.Headers.Set("Date", DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH:mm:ss G\\MT"));
Update: Doh! Silly me. I was using the Date object and even tried to force the string I wanted. Thankfully that just lead me to trying something else.
Request.Headers.Get("Date")
I will leave this question up for those that may run into this silly problem I did. Critical thinking skills... I feel like a dope. >:|
Upvotes: 6
Views: 6619
Reputation: 138
There is no direct way to set date header format except using reflection
Have a look at these links for how to use reflection workaround
c-sharp-httpwebrequest-date-header-formatting
asp-net-httpwebrequest-date-header-workaround
Upvotes: 1
Reputation: 1133
Use this instead to get the string representation.
Request.Headers.Get("Date")
Upvotes: 0