HTTPWebResponse + StreamReader Very Slow

前端 未结 9 1240
粉色の甜心
粉色の甜心 2020-12-01 01:47

I\'m trying to implement a limited web crawler in C# (for a few hundred sites only) using HttpWebResponse.GetResponse() and Streamreader.ReadToEnd() , also tried using Strea

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 02:00

    Thank you all for answers, they've helped me to dig in proper direction. I've faced with the same performance issue, though proposed solution to change application config file (as I understood that solution is for web applications) doesn't fit my needs, my solution is shown below:

    HttpWebRequest webRequest;
    
    webRequest = (HttpWebRequest)System.Net.WebRequest.Create(fullUrl);
    webRequest.Method = WebRequestMethods.Http.Post;
    
    if (useDefaultProxy)
    {
        webRequest.Proxy = System.Net.WebRequest.DefaultWebProxy;
        webRequest.Credentials = CredentialCache.DefaultCredentials;
    }
    else
    {
        System.Net.WebRequest.DefaultWebProxy = null;
        webRequest.Proxy = System.Net.WebRequest.DefaultWebProxy;
    }
    

提交回复
热议问题