2015-10-20 343 views
2

守則要求的範圍不合適,我嘗試:遠程服務器返回錯誤:(416)在C#

string contents = string.Empty; 

using (var wc = new System.Net.WebClient()) 
{  
    contents = wc.DownloadString("http://www.bizjournals.com/albany/blog/health-care/2015/10/what-this-local-bank-did-to-control-health-care.html");  
} 

但其拋出錯誤

The remote server returned an error: (416) Requested Range Not Satisfiable

回答

1

看來,一些網絡服務器可能會返回一個如果您的客戶端不發送User-Agent頭,則爲416。嘗試像這樣添加標頭:

wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705"); 
+0

適合我,謝謝。 –

相關問題