【发布时间】:2015-02-20 14:16:08
【问题描述】:
我正在尝试从 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
【问题讨论】:
-
你用过 Wireshark 或类似的东西来看看时间都去哪儿了?
-
我没用过WS因为不知道怎么操作
-
@BartłomiejSobieszek 然后读入 Wireshark
-
我刚刚测试了您的代码,它似乎运行得尽可能快。你有防火墙或中间的东西吗?
-
好的,我解决了这个问题,我必须将代理设置为 null :)
标签: c# performance webclient downloadstring