Date Header doesn't appear to be added to request

172 views
Skip to first unread message

Stuart Bale

unread,
Mar 15, 2012, 12:08:03 AM3/15/12
to rest...@googlegroups.com
How do I ensure that the Date header is added to the Request?

And how do I get the value that the Date header will contain?

Stuart

unread,
May 11, 2012, 11:09:39 PM5/11/12
to RestSharp
How did you solve this?

Andrew Young

unread,
May 12, 2012, 12:28:01 AM5/12/12
to rest...@googlegroups.com
This is a bug. There is currently a pull request for this. https://github.com/restsharp/RestSharp/pull/275

John Sheehan

unread,
May 14, 2012, 7:21:29 PM5/14/12
to rest...@googlegroups.com
This will only be supported in .NET 4.0, when the next version ships
(no timeline).

unread,
May 16, 2012, 8:24:52 AM5/16/12
to RestSharp
_restrictedHeaderActions.Add("Date", (r, v) => { /* Set by
system */
            float dotnetVersion = float.Parse(DetermineFramework());
            if (dotnetVersion >= 4.0)
            {
                PropertyInfo pinfo = r.GetType().GetProperty("Date");
                pinfo.SetValue(r, DateTime.Parse(v).ToUniversalTime(),
null);
            }
            else
            {
                Type type = r.Headers.GetType();
                MethodInfo method =
type.GetMethod("AddWithoutValidate",
                    BindingFlags.Instance | BindingFlags.NonPublic);
                method.Invoke(r.Headers, new[] { "Date", v });
            } });

Maybe userfull

Hajdrik Attila

unread,
May 16, 2012, 1:33:10 PM5/16/12
to rest...@googlegroups.com
Don't forget to add CultureInfo.InvariantCulture parameter to float.Parse
to get it right,

Perhaps DateTime.Parse should need a culture info parameter?

Because of the NonPublic reflection I think that this code should be only
added for the .Net 4.0 targeted source, because reflection will fail on
non-public members.
________________________________

Sent from Exchange Server 2010
Reply all
Reply to author
Forward
0 new messages