473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

HTTPWebRequest Date Header

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
6 4125
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: TJO | last post by:
Can someone at MS please reply to this. I am trying to post data so a web form via ssl with the following code. I keep getting this error: "The underlying connection was closed: Could not...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
8
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've...
0
by: boxboy | last post by:
Hi, I'm writing a console application and am having a problem with HttpWebRequest when posting data to a webserver. A "System.Net.WebException: The server committed a protocol violation" is always...
0
by: barrybevel | last post by:
Hi, I'm trying to login to the www.vodafone.ie website using HttpWebRequest. It works fine with IE/Firefox and the .NET Web Control too, just not with my code. I think it's a redirect 302...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.