Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>There are some things to clarify:</strong></p> <ul> <li><p>Your date pattern is incorrect.</p></li> <li><p>The HttpWebRequest <code>request.Date</code> header can be only get modified in .NET Framework 4 and according to the documentation, the <code>System.Net</code> namespace will always write this header as standard form using <strong>GMT (UTC) format</strong>. So, whatever you can do to format your date as you want, won't work!</p></li> <li><p>In other .NET framework versions you won't be able to modify the HttpWebRequest <code>request.Date</code> header because it will use the actual date in correct GMT (UTC) format unless you use a kind of hack to set your own date and format (see below).</p></li> </ul> <hr> <p><strong>Solution for your problem (tested and working):</strong></p> <p><em>Your imports:</em></p> <pre><code>using System.Net; using System.Reflection; </code></pre> <p><em>Get today's date in format: Mon, 16 Jul 2012 01:16:18 -0000</em></p> <pre><code>string today = String.Format("{0:ddd,' 'dd' 'MMM' 'yyyy' 'HH':'mm':'ss' 'K}", DateTime.Now); </code></pre> <p><em>Here comes the tricky thing, you can hack the HttpWebRequest date header by doing this:</em></p> <p><em>(Don't do <code>request.Date = something;</code> anymore, replace it with the following)</em></p> <pre><code>MethodInfo priMethod = request.Headers.GetType().GetMethod("AddWithoutValidate", BindingFlags.Instance | BindingFlags.NonPublic); priMethod.Invoke(request.Headers, new[] { "Date", today }); </code></pre> <p><em>Get the date from your request (just to test):</em></p> <pre><code>// "myDate" will output the same date as the first moment: // Mon, 16 Jul 2012 01:16:18 -0000 // As you can see, you will never get this again: // Mon, 16 Jul 2012 07:16:18 GMT string myDate = request.Headers.Get("Date"); </code></pre> <hr> <p><strong>At this point you had successfully set your own format and date value to the HttpWebRequest date header!</strong></p> <p>Hope this helps :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload