C# Bug in WebRequest
I have discovered what I believe is a bug in the C# framework.
I have a simple code that sends a Http webdav request
req = (HttpWebRequest)WebRequest.Create(url);
req.Method = « PROPFIND »;
req.Headers = new WebHeaderCollection();
// I dunno what’s for, but Sharepoint throws error 404 if it is not set
req.Headers.Set(« translate », « f »);
req.Headers.Set(« Depth », depth.ToString());
// encode en UTF8 le corp de message à transmettre
byte[] bytes = Encoding.UTF8.GetBytes((string)query);
req.ContentType = « text/xml »;
req.ContentLength = bytes.LongLength;
RequestStream = req.GetRequestStream();
RequestStream.Write(bytes, 0, bytes.Length);
RequestStream.Close();
HttpWebResponse webResp = (HttpWebResponse)req.GetResponse();
// Note : C# has no constant for http status code WEBDAV_MULTI
if (((int)webResp.StatusCode) == 207)
{
// handle web response
}
Everything works fine most of the time.
This is a typical http dump
`
PROPFIND /path/to/foo.bar HTTP/1.1
translate: f
Depth: 0
Content-Type: text/xml
Host: httpserver
Content-Length: 90
Expect: 100-continue
HTTP/1.1 100 Continue
< ?xml version=”1.0” encoding=”UTF-8”?>
Date: Mon, 27 Dec 2010 09:42:27 GMT
Server: IBM_HTTP_Server/2.0.47.1 Apache/2.0.47 (Unix) DAV/2
Transfer-Encoding: chunked
Content-Type: text/xml; charset=”utf-8”</p>
37b
< ?xml version="1.0" encoding="utf-8"?>
<d:multistatus xmlns: D="DAV:" xmlns:ns0="DAV:">
</d:multistatus>
`
Now, sometimes, C# hangs on
`
PROPFIND /path/to/foo.bar HTTP/1.1
translate: f
Depth: 0
Content-Type: text/xml
Host: httpserver
Content-Length: 90
Expect: 100-continue
HTTP/1.1 100 Continue
`
It is only 100 seconds afterwards that the IBM http server sends a timeout.
Why is the request never send? [Mironelli gives a workaround](http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx#1908)
```
req.ServicePoint.Expect100Continue = false;
```
That way, the request contains the full body from the beginning, instead of [a check for the server capabilities](http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3).