C# HttpWebRequest Date Header Formatting

后端 未结 4 962
無奈伤痛
無奈伤痛 2020-12-30 13:13

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\"

4条回答
  •  独厮守ぢ
    2020-12-30 13:46

    The HttpWebRequest will properly format the Date by itself. Your problem is that you must submit a valid current date. You have to check that the clock of the computer is accurate, and then that you are sending the proper date regarding Time Zones and UTC and GMT issues...

    try both:

    request.Date = DateTime.Now;
    request.Date = DateTime.UtcNow;
    

    one of that needs to work (and both should work if HttpWebRequest is properly implemented).

    In case that doesn't work, use fiddler to see what's going on, and fix the request by hand until you get it working

提交回复
热议问题