By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,953 Members | 1,438 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,953 IT Pros & Developers. It's quick & easy.

HTTPWebRequest Date Header

P: n/a
Hi,

I am having problems setting the HttpWebRequest Date header. I understand
that it is a restricted header and I do receive the
"This header must be modified with the appropriate property." Is there a
way to make sure that the date header is sent over or a way to work around
this exception?

Here's a sample of the code:

System.Net.HttpWebRequest wr;
wr = (HttpWebRequest)WebRequest.Create(requestUrl);
System.Net.WebHeaderCollection whcHeaders = wr.Headers;
whcHeaders.Add(@"Date" , DateTime.Now.ToString("r"));

Thanks,
Mike
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Mike,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 19 '05 #2

P: n/a
Hi Mike,

Welcome to ASPNET newsgroup.
As for the "Date" http header you mentioned, based on the HttpWebRequest's
Documentation, it is not included in the headers collection , also there is
no property in the HttpWebRequest class for us to manually adjust it since
it is automatically assigned to the current Date by runtime.

#HttpWebRequest.Headers Property
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemnethttpwebrequestclassheaderstopic.asp

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Mike Koerner" <mi**********@newsgroup.nospam>
| Subject: HTTPWebRequest Date Header
| Date: Fri, 16 Sep 2005 15:58:48 -0700
| Lines: 19
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#U**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.175.2.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125237
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| I am having problems setting the HttpWebRequest Date header. I
understand
| that it is a restricted header and I do receive the
| "This header must be modified with the appropriate property." Is there a
| way to make sure that the date header is sent over or a way to work
around
| this exception?
|
| Here's a sample of the code:
|
| System.Net.HttpWebRequest wr;
| wr = (HttpWebRequest)WebRequest.Create(requestUrl);
| System.Net.WebHeaderCollection whcHeaders = wr.Headers;
| whcHeaders.Add(@"Date" , DateTime.Now.ToString("r"));
|
| Thanks,
| Mike
|
|
|

Nov 19 '05 #3

P: n/a
Hi,

Thanks for the response. I understand that the Date header is assigned at
runtime. Is there a way to include it in the headers sent by
HTTPWebRequest? It is not currently being sent. Do I have to create a
class derived from HTTPWebRequest to send it?

Thanks,
Mike
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:33*************@TK2MSFTNGXA01.phx.gbl...
Hi Mike,

Welcome to ASPNET newsgroup.
As for the "Date" http header you mentioned, based on the HttpWebRequest's
Documentation, it is not included in the headers collection , also there
is
no property in the HttpWebRequest class for us to manually adjust it since
it is automatically assigned to the current Date by runtime.

#HttpWebRequest.Headers Property
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemnethttpwebrequestclassheaderstopic.asp

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Mike Koerner" <mi**********@newsgroup.nospam>
| Subject: HTTPWebRequest Date Header
| Date: Fri, 16 Sep 2005 15:58:48 -0700
| Lines: 19
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#U**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.175.2.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125237
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| I am having problems setting the HttpWebRequest Date header. I
understand
| that it is a restricted header and I do receive the
| "This header must be modified with the appropriate property." Is there
a
| way to make sure that the date header is sent over or a way to work
around
| this exception?
|
| Here's a sample of the code:
|
| System.Net.HttpWebRequest wr;
| wr = (HttpWebRequest)WebRequest.Create(requestUrl);
| System.Net.WebHeaderCollection whcHeaders = wr.Headers;
| whcHeaders.Add(@"Date" , DateTime.Now.ToString("r"));
|
| Thanks,
| Mike
|
|
|

Nov 19 '05 #4

P: n/a
Thanks for your response Mike,

For the HTTPwebRequest, I'm afraid the current implementation has hidden
the Date Header's generation internally and dosn't expose any means for us
to intercepting the header collection. If you do need to manually involve
such custom headers in your HTTP communication(base on the RFC of HTTP 1.1
, date header is not required in client request message), I think we may
need to write our own HTTP message/header generating class rather than use
the HttpWebRequest, also I don't think derived class from it can intercept
the header generation.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Mike Koerner" <mi**********@newsgroup.nospam>
| References: <#U**************@TK2MSFTNGP09.phx.gbl>
<33*************@TK2MSFTNGXA01.phx.gbl>
| Subject: Re: HTTPWebRequest Date Header
| Date: Mon, 19 Sep 2005 08:50:15 -0700
| Lines: 83
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#g**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.175.2.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125559
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| Thanks for the response. I understand that the Date header is assigned
at
| runtime. Is there a way to include it in the headers sent by
| HTTPWebRequest? It is not currently being sent. Do I have to create a
| class derived from HTTPWebRequest to send it?
|
| Thanks,
| Mike
|
|
| "Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
| news:33*************@TK2MSFTNGXA01.phx.gbl...
| > Hi Mike,
| >
| > Welcome to ASPNET newsgroup.
| > As for the "Date" http header you mentioned, based on the
HttpWebRequest's
| > Documentation, it is not included in the headers collection , also
there
| > is
| > no property in the HttpWebRequest class for us to manually adjust it
since
| > it is automatically assigned to the current Date by runtime.
| >
| > #HttpWebRequest.Headers Property
| >
http://msdn.microsoft.com/library/de...us/cpref/html/
| > frlrfsystemnethttpwebrequestclassheaderstopic.asp
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| > --------------------
| > | From: "Mike Koerner" <mi**********@newsgroup.nospam>
| > | Subject: HTTPWebRequest Date Header
| > | Date: Fri, 16 Sep 2005 15:58:48 -0700
| > | Lines: 19
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <#U**************@TK2MSFTNGP09.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 12.175.2.2
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:125237
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hi,
| > |
| > | I am having problems setting the HttpWebRequest Date header. I
| > understand
| > | that it is a restricted header and I do receive the
| > | "This header must be modified with the appropriate property." Is
there
| > a
| > | way to make sure that the date header is sent over or a way to work
| > around
| > | this exception?
| > |
| > | Here's a sample of the code:
| > |
| > | System.Net.HttpWebRequest wr;
| > | wr = (HttpWebRequest)WebRequest.Create(requestUrl);
| > | System.Net.WebHeaderCollection whcHeaders = wr.Headers;
| > | whcHeaders.Add(@"Date" , DateTime.Now.ToString("r"));
| > |
| > | Thanks,
| > | Mike
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #5

P: n/a
Hi,

Thanks for trying to help me out.

I worked around the HTTPWebRequest Date header limitation by implementing a
HTTP TCPClient. I don't need anything fancy, just posting data to a URL
with specific headers. Here's a sample:

string requestUrl = "http://localhost/MyTestPost.aspx";
System.Uri uri = new Uri(requestUrl);
string server = uri.Host;
Int32 port = uri.Port;

System.Net.Sockets.TcpClient client = new
System.Net.Sockets.TcpClient(server, port);
string requestMethod = "POST " + uri.LocalPath + " HTTP/1.0\r\n";
string requestHeaders = "";
string payload = "MyTest\r\n";

requestHeaders += "Date: " + DateTime.Now.ToString("r") + "\r\n";
requestHeaders += "\r\n";

Byte[] data = System.Text.Encoding.ASCII.GetBytes(requestMethod +
requestHeaders + payload);
// Send the message to the connected TcpServer.
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
stream.Flush();

string responseData="";

// Receive the TcpServer.response.
for(int i=0;i<100;i++)
{
if (stream.DataAvailable)
{
break;
}
System.Threading.Thread.Sleep(100);
}

Byte[] bytes = new byte[1024];
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while (stream.DataAvailable)
{
int count = stream.Read(bytes, 0, 1024);
if (count == 0)
{
break;
}
sb.Append(System.Text.Encoding.UTF8.GetString(byte s, 0, count));
}
responseData = sb.ToString();
// Close everything.
client.Close();
"Mike Koerner" <mi**********@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I am having problems setting the HttpWebRequest Date header. I understand
that it is a restricted header and I do receive the
"This header must be modified with the appropriate property." Is there a
way to make sure that the date header is sent over or a way to work around
this exception?

Here's a sample of the code:

System.Net.HttpWebRequest wr;
wr = (HttpWebRequest)WebRequest.Create(requestUrl);
System.Net.WebHeaderCollection whcHeaders = wr.Headers;
whcHeaders.Add(@"Date" , DateTime.Now.ToString("r"));

Thanks,
Mike

Nov 19 '05 #6

P: n/a
Thanks for your further followup.

That's cool to utilize the existing TcpCliet class.
Thanks for sharing your code with us.

Also, if there're any thing else we can help later, please feel free to
post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Mike Koerner" <mi**********@newsgroup.nospam>
| References: <#U**************@TK2MSFTNGP09.phx.gbl>
| Subject: Re: HTTPWebRequest Date Header
| Date: Tue, 20 Sep 2005 10:05:46 -0700
| Lines: 81
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.1830
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
| Message-ID: <eP**************@TK2MSFTNGP14.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.175.2.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:125864
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| Thanks for trying to help me out.
|
| I worked around the HTTPWebRequest Date header limitation by implementing
a
| HTTP TCPClient. I don't need anything fancy, just posting data to a URL
| with specific headers. Here's a sample:
|
| string requestUrl = "http://localhost/MyTestPost.aspx";
| System.Uri uri = new Uri(requestUrl);
| string server = uri.Host;
| Int32 port = uri.Port;
|
| System.Net.Sockets.TcpClient client = new
| System.Net.Sockets.TcpClient(server, port);
| string requestMethod = "POST " + uri.LocalPath + " HTTP/1.0\r\n";
| string requestHeaders = "";
| string payload = "MyTest\r\n";
|
| requestHeaders += "Date: " + DateTime.Now.ToString("r") + "\r\n";
| requestHeaders += "\r\n";
|
| Byte[] data = System.Text.Encoding.ASCII.GetBytes(requestMethod +
| requestHeaders + payload);
| // Send the message to the connected TcpServer.
| NetworkStream stream = client.GetStream();
| stream.Write(data, 0, data.Length);
| stream.Flush();
|
| string responseData="";
|
| // Receive the TcpServer.response.
| for(int i=0;i<100;i++)
| {
| if (stream.DataAvailable)
| {
| break;
| }
| System.Threading.Thread.Sleep(100);
| }
|
| Byte[] bytes = new byte[1024];
| System.Text.StringBuilder sb = new System.Text.StringBuilder();
| while (stream.DataAvailable)
| {
| int count = stream.Read(bytes, 0, 1024);
| if (count == 0)
| {
| break;
| }
| sb.Append(System.Text.Encoding.UTF8.GetString(byte s, 0, count));
| }
|
|
| responseData = sb.ToString();
| // Close everything.
| client.Close();
|
|
| "Mike Koerner" <mi**********@newsgroup.nospam> wrote in message
| news:%2****************@TK2MSFTNGP09.phx.gbl...
| > Hi,
| >
| > I am having problems setting the HttpWebRequest Date header. I
understand
| > that it is a restricted header and I do receive the
| > "This header must be modified with the appropriate property." Is there
a
| > way to make sure that the date header is sent over or a way to work
around
| > this exception?
| >
| > Here's a sample of the code:
| >
| > System.Net.HttpWebRequest wr;
| > wr = (HttpWebRequest)WebRequest.Create(requestUrl);
| > System.Net.WebHeaderCollection whcHeaders = wr.Headers;
| > whcHeaders.Add(@"Date" , DateTime.Now.ToString("r"));
| >
| > Thanks,
| > Mike
| >
|
|
|

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.