我正在尝试从 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/