Wednesday, January 7, 2015

WebRequest.Create is slow? This one for you

WebRequest.Create indeed very slow. You can look previous post about my problem...

the problem is WebRequest.Create and GetResponse 

lets solving this...

request.Proxy = null;
using (var response = (HttpWebResponse)request.GetResponse())
                StreamReader stream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
                string result = stream.ReadToEnd();

first part is proxy to null. ( WebRequest auto detect proxy setting in IE )
Second part is wrapping GetResponse with using

Plus add this little thing :D for connection limit :D

System.Net.ServicePointManager.DefaultConnectionLimit = 1000; //or some other number > 4
And maybe you need this one below to... ( I add here just in case ) :D
System.Net.ServicePointManager.Expect100Continue = false;