C# HttpWebRequest Date Header Formatting

Viewed 12040

I'm making a HttpWebRequest to S3, and I'm trying to set the Date header to something like this:

"Mon, 16 Jul 2012 01:16:18 -0000"

Here is what I've tried:

string pattern = "ddd, dd MMM yyyy HH:mm:ss -0000";
request.Date = DateTime.ParseExact("Mon, 16 Jul 2012 01:16:18 -0000", pattern, null);

But, when I look at the headers of the request, here's what I get:

request.Headers.Get("Date");
// "Mon, 16 Jul 2012 07:16:18 GMT"

I believe this may the reason for a 403 on the request. The AWS error docs mention:

403 Forbidden - The difference between the request time and the server's time is too large.

Any suggestions for getting this date sorted out would be greatly appreciated. Thanks!

4 Answers
Related