Thursday, January 8, 2015

WebRequest.Create is slow? This one for you

WebRequest.Create indeed very slow. You can look previous post about my problem... http://tulisanlain.blogspot.com/2014/07/breakthrough-limit-maximum-number.html

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();
                stream.Close();
}

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;