A
ajdavis
Hello, folks. A strange error that I finally tracked down with the
Ethereal packet sniffer:
Using .NET Compact Framework 1.0.3111 and programming C# in Visual
Studio .NET 7.1.3088, I create an HttpWebRequest. The first time, the
ProtocolVersion is 1.1 and the Host is correctly set in the HTTP
header. The second & all subsequent times, the same code produces a
request with ProtocolVersion 1.0, and the Host string is empty. This
sort of HTTP request fails for most hosts.
I'd love it if a few people w/ different versions of Windows CE, Visual
Studio, .NETCF, etc. tried this out. 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.
Jesse.
Ethereal packet sniffer:
Using .NET Compact Framework 1.0.3111 and programming C# in Visual
Studio .NET 7.1.3088, I create an HttpWebRequest. The first time, the
ProtocolVersion is 1.1 and the Host is correctly set in the HTTP
header. The second & all subsequent times, the same code produces a
request with ProtocolVersion 1.0, and the Host string is empty. This
sort of HTTP request fails for most hosts.
I'd love it if a few people w/ different versions of Windows CE, Visual
Studio, .NETCF, etc. tried this out. 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.
Jesse.