Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest Date Header Format

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. >:|

like image 601
Joshua W Avatar asked Nov 05 '11 21:11

Joshua W


1 Answers

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

like image 71
Mohamed Abbas Avatar answered Oct 13 '22 00:10

Mohamed Abbas