I am consuming a third party API which expects an HTTP header
value as below (using the format below).
Date: 2017-10-15T14:25:21Z
When I try to add the header as below, I am getting invalid date time format error (when the client inject the header during runtime)
client.DefaultRequestHeaders.Add("Date", "2017-10-15T14:25:21Z");
So I change the code above to as below
client.DefaultRequestHeaders.Date = DateTime.UtcNow;
However, the API throws back an exception "Hmac timestamp 2019-01-02 is not a valid ISO8601 dateTime"
How do I pass the expected date time format in the HTTP request header?
EDIT
- I know how to get a date string in a specified format. What I am asking here is how do I pass a UTC date object to HTTP header as below with a specific format. I also realise that datetime object cant have a format in it.
**client.DefaultRequestHeaders.Date = DateTime.UtcNow**