System.Net.WebClient unreasonably slow

后端 未结 8 1736
北荒
北荒 2020-11-30 01:46

When using the System.Net.WebClient.DownloadData() method I\'m getting an unreasonably slow response time.

When fetching an url using the WebClient class in .NET it

8条回答
  •  囚心锁ツ
    2020-11-30 02:27

    I had that problem with WebRequest. Try setting Proxy = null;

        WebClient wc = new WebClient();
        wc.Proxy = null;
    

    By default WebClient, WebRequest try to determine what proxy to use from IE settings, sometimes it results in like 5 sec delay before the actual request is sent.

    This applies to all classes that use WebRequest, including WCF services with HTTP binding. In general you can use this static code at application startup:

    WebRequest.DefaultWebProxy = null;
    

提交回复
热议问题