A
ajdavis
Hello, folks. Sorry for the cross-posting, but I seem to have found a
horrendous bug in the .NETCF, and no one's responding on the
compactframework newsgroup. Basically, I'm doing HTTP requests in C#,
and the first HttpWebRequest works fine, but after that (until I
restart my program) all the requests fail. Sniffing packets with
Ethereal, I saw that the first request used HTTP Version 1.1 and
correctly set the Host in the header, but the others had HTTP Version
1.0 and no Host.
This seems like a huge problem. Is anyone out there doing multiple
HTTP requests in a .NETCF program? Using C#? Does it work?
I'm using .NET Compact Framework 1.0.3111 and programming C# in Visual
Studio .NET 7.1.3088.
Repro:
Make a new Smart Device Application project, in the next dialog select
"Pocket PC" or "Windows CE" and "Windows Application". Then in the
autogenerated Form1.cs, add "using System.Net;" at the top, and insert
the following in the Form1 constructor, below InitializeComponent():
TextBox output = new TextBox();
output.Multiline = true; output.ScrollBars = ScrollBars.Both;
output.Size = new Size(180, 220); this.Controls.Add(output);
for (int i = 0; i < 2; i++)
{
HttpWebResponse response = null;
HttpWebRequest request = null;
try
{
Uri url = new Uri("http://foobar.com/");
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 10 * 1000; // milliseconds
request.Method = "GET";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version11;
response = (HttpWebResponse)request.GetResponse();
output.Text += string.Format("Received response of {0}
bytes\r\n",
response.ContentLength);
}
catch (Exception e)
{
output.Text += "Exception: " + e.ToString() + "\r\n";
}
finally
{
if (response != null) response.Close();
}
output.Text += "Version: " + request.ProtocolVersion.ToString()
+
"\r\n";
output.Text += "Host: " + request.Headers.Get("Host") +
"\r\n";
output.Text += "======\r\n";
}
On my setup, I get the following output:
Received response of 2146 bytes
Version: 1.1
Host: foobar.com
======
Exception: System.Net.WebException:The remote server returned an
error: (503) Server Unavailable.
Version: 1.0
Host:
======
Notice how the Version is 1.0 and Host is empty in the second, failed,
request. Weird, huh? I filed a bug with MS, ID FDBK31733. After 5
days, no action. I'm about to re-implement HTTP over sockets; I'll
post my code to the compactframework newsgroup when I do.
Jesse.
horrendous bug in the .NETCF, and no one's responding on the
compactframework newsgroup. Basically, I'm doing HTTP requests in C#,
and the first HttpWebRequest works fine, but after that (until I
restart my program) all the requests fail. Sniffing packets with
Ethereal, I saw that the first request used HTTP Version 1.1 and
correctly set the Host in the header, but the others had HTTP Version
1.0 and no Host.
This seems like a huge problem. Is anyone out there doing multiple
HTTP requests in a .NETCF program? Using C#? Does it work?
I'm using .NET Compact Framework 1.0.3111 and programming C# in Visual
Studio .NET 7.1.3088.
Repro:
Make a new Smart Device Application project, in the next dialog select
"Pocket PC" or "Windows CE" and "Windows Application". Then in the
autogenerated Form1.cs, add "using System.Net;" at the top, and insert
the following in the Form1 constructor, below InitializeComponent():
TextBox output = new TextBox();
output.Multiline = true; output.ScrollBars = ScrollBars.Both;
output.Size = new Size(180, 220); this.Controls.Add(output);
for (int i = 0; i < 2; i++)
{
HttpWebResponse response = null;
HttpWebRequest request = null;
try
{
Uri url = new Uri("http://foobar.com/");
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Timeout = 10 * 1000; // milliseconds
request.Method = "GET";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version11;
response = (HttpWebResponse)request.GetResponse();
output.Text += string.Format("Received response of {0}
bytes\r\n",
response.ContentLength);
}
catch (Exception e)
{
output.Text += "Exception: " + e.ToString() + "\r\n";
}
finally
{
if (response != null) response.Close();
}
output.Text += "Version: " + request.ProtocolVersion.ToString()
+
"\r\n";
output.Text += "Host: " + request.Headers.Get("Host") +
"\r\n";
output.Text += "======\r\n";
}
On my setup, I get the following output:
Received response of 2146 bytes
Version: 1.1
Host: foobar.com
======
Exception: System.Net.WebException:The remote server returned an
error: (503) Server Unavailable.
Version: 1.0
Host:
======
Notice how the Version is 1.0 and Host is empty in the second, failed,
request. Weird, huh? I filed a bug with MS, ID FDBK31733. After 5
days, no action. I'm about to re-implement HTTP over sockets; I'll
post my code to the compactframework newsgroup when I do.
Jesse.