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. >:|
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With