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" <
[email protected]>
| References: <#
[email protected]>
| 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: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.175.2.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.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(bytes, 0, count));
| }
|
|
| responseData = sb.ToString();
| // Close everything.
| client.Close();
|
|
| | > 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
| >
|
|
|