Tuesday, July 12, 2011

c# .NET HttpWebRequest slow - Expect 100 continue!

Another tech stuff, at least as I am not posting lately. So, we were sending HTTP requestso the server and against a previous (3rd party) version it was extremely slow. Any browsing would suggest to change buffering, async mode or turning off proxy, but none helped.

When we changed POST to GET, this problem dismissed!
When we rewrote using sockets, the problem dismissed, but could not take the risk of an own implementation on a production system.

Profiling showed the bottleneck is this line:
HttpWebResponse r = (HttpWebResponse)request.GetResponse();

the poll method. Finally the solution was
Expect 100 Continue
Never heard of? :) What a surprise, turn itt off and give it a try. For further explanation search the web for it.

System.Net.ServicePointManager.Expect100Continue = false;
or
request.ServicePoint.Expect100Continue = false;

Good luck.