我開發了一個循環發送請求到網站的小程序。 爲了從網頁上獲得我需要的信息,然後存儲到我的數據庫。WebClient拋出異常遠程服務器返回一個錯誤:(507)存儲不足
約1400個請求。
我在開發機器和Windows Azure虛擬機上運行它。
起初,它在兩臺機器(第一天)上運行良好。 但我在第二天在Windows Azure VM上運行它之後。 這是拋出異常。
Web Exception: System.Net.WebException: The remote server returned an error: (507) Insufficient Storage. at System.Net.WebClient.OpenRead(Uri address) at System.Net.WebClient.OpenRead(String address) at StockChecker.MainWindow.Worker_DoWork(Object Sender, DoWorkEventArgs e)
但是在開發機器上沒有問題。
它發生了什麼。目標網站是否被檢測爲機器人? 如何解決這個問題。
這是我的代碼。
WebClient client = new WebClient();
List<tbmProduct> prodList = // Get data from my database;
foreach (var prod in prodList)
{
string content;
string link = prod.SupplierUrl;
try
{
using (StreamReader reader = new StreamReader(client.OpenRead(link)))
{
content = reader.ReadToEnd();
// Do something. Update my database.
}
}
catch (WebException ex)
{
// write log
}
catch (Exception ex)
{
// write log
}
}