c# - WebClient 下载字符串(几个字符页面)太慢了

标签 c# performance webclient downloadstring

我正在尝试从 URL 下载字符串。不幸的是,它非常慢。

这是我的代码:

    // One of these types for two bad solutions anyway
    // byte[] result = new byte[12];
    // string result;
    using (var webClient = new System.Net.WebClient())
    {
        String url = "http://bg2.cba.pl/realmIP.txt";
        //result = webClient.DownloadString(url); // slow as hell
        //webClient.OpenRead(url).Read(result, 0, 12); // even slower
    }

大约需要4-5秒,这对我来说似乎很不合适......

这个url的内容是IP

 XX.YYY.ZZ.FF

最佳答案

已修复,我想很抱歉在这里提出这个问题,但是......这是工作代码

string result;
using (var webClient = new System.Net.WebClient())
{
    webClient.Proxy=null;
    String url = "http://bg2.cba.pl/realmIP.txt";
    result = webClient.DownloadString(url);
}

只需将 Proxy 设置为 null

关于c# - WebClient 下载字符串(几个字符页面)太慢了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27603404/

相关文章:

c# - 如何使用 Trello.NET 从 Trello 获取所有看板?

c# - 流利的断言;结合集合和对象图比较断言

c# - 使用 XPath 测试当前节点

c# - XML 下载适用于模拟器,但不适用于手机

c# - 当我使用带有 Silverlight 4.0 的 WebClient 调用 aspx 页面时,无法执行 Response.Redirect

c# - 有没有办法用 WebClient 做一个 PUT?

c# - 在 WPF 中使用 datatriggers 设置 ItemsSource 属性

c# - IEnumerable.Count() 或 ToList().Count

c# - 如何在C#中获取主板传感器读数

javascript - 更好更快的评估方法?