Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebClient download string (a few chars page) is so slow

I am trying to download a string from an URL. Unfortunately, it is very slow.

Here is my code:

    // 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
    }

It takes about 4-5 seconds, which seems very inappropriate to me...

Content of this url is IP

 XX.YYY.ZZ.FF
like image 952
Bartłomiej Sobieszek Avatar asked Dec 04 '22 04:12

Bartłomiej Sobieszek


2 Answers

Fixed, sorry for putting this question here I guess, but... here is working code

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

Just set Proxy to null

like image 116
Bartłomiej Sobieszek Avatar answered Dec 27 '22 11:12

Bartłomiej Sobieszek


It is clearly a problem with you line/pc/firewall

You can test it online:

http://goo.gl/XRqLjn

it takes about 500 milliseconds

enter image description here

UPDATE after your own answer

If you want to use no proxy you should use GetEmptyWebProxy() as stated on msdn:

webClient.Proxy=GlobalProxySelection.GetEmptyWebProxy();
like image 26
giammin Avatar answered Dec 27 '22 12:12

giammin