簡體   English   中英

來自WebClient的錯誤:“遠程服務器返回錯誤:(503)服務器不可用”

[英]Error from WebClient: “The remote server returned an error: (503) Server Unavailable”

using (var wc = new WebClient())
{
    Uri urls = new Uri(url);
    wc.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36";
    dokuman.Load(wc.OpenRead(urls), Encoding.UTF8);
}

dokuman.Load(wc.OpenRead(urls), Encoding.UTF8);

遠程服務器返回錯誤:(503)服務器不可用。

有時我會收到此錯誤。 我們該如何解決呢?

我使用這個實用程序功能,它也支持代理

 public static string GetPageHtml(string link, System.Net.WebProxy proxy = null)
        {
            System.Net.WebClient client = new System.Net.WebClient() { Encoding = Encoding.UTF8 };
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            if (proxy != null)
            {
                client.Proxy = proxy;
            }

            using (client)
            {
                try
                {
                    return client.DownloadString(link);
                }
                catch (Exception ex)
                {
                    return null;
                }
            }

        }

嘗試一下,如果它不起作用,那么您可能因為快速提出請求而被Google阻止了,為避免被阻止,您應該使用網絡代理或在請求之間進行合理的暫停。

var Html = GetPageHtml("https://www.google.com.tr/search?sclient=psy-ab&site=&source=hp&q=cars+&btnG=Ara");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM