0

I get page source with below code. after it takes second page's source code it gives web exception which says "The operation has timed out" How can I solve this?

     Uri url = new Uri(urlAddress);
        WebClient client = new WebClient();
        client.Encoding = System.Text.Encoding.GetEncoding("windows-1254");                     
        string htlm = client.DownloadString(url);
        return htlm;
ruqo
  • 65
  • 2
  • 14
  • You need to extend the connection timeout of the client.This is done by inheriting the existing web client and increasing the timeout of the web request. There is a better explanation on how to do it here http://stackoverflow.com/questions/1789627/how-to-change-the-timeout-on-a-net-webclient-object – nsgocev Jul 03 '14 at 11:43
  • @nsgocev I tried but it doenst work I guess because the asker says the site too slow that causes the time out. The site I try to get source isn't slow – ruqo Jul 03 '14 at 12:10
  • The site is quick in your browser but times out in your code? How long does it take to timeout? – DavidG Jul 03 '14 at 12:15
  • do you mind giving the link? – korrupt Jul 03 '14 at 12:17
  • e.g these 3 links http://www.hurriyet.com.tr/yazarlar/24420135.asp , http://www.hurriyet.com.tr/yazarlar/24412055.asp , http://www.hurriyet.com.tr/yazarlar/24408289.asp @DavidG it takes first and second in like 2-3 seconds. but when it comes to third it stucks – ruqo Jul 03 '14 at 12:35
  • I've tried all 3 addresses using the same code as you and it works fine. Do you have any proxy server or firewall in place? – DavidG Jul 03 '14 at 13:01

1 Answers1

2

I found this question DownloadString timed out . It is identical to your question. But in this case you should use something like

    oClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0");

instead of

 oClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)");
Community
  • 1
  • 1
korrupt
  • 200
  • 11