简体   繁体   中英

DownloadString and web exception(The operation has timed out)

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;

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;)");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM