次のようにWebサイトからデータを読み取っています。
webRequestObj = (HttpWebRequest)WebRequest.Create("http://localhost/503errorPage.php");
theResponse = webRequestObj.GetResponse();
theResponseStream = theResponse.GetResponseStream();
theStreamReader = new StreamReader(theResponseStream);
theWholePage = theStreamReader.ReadToEnd();
503 エラーのあるページに到達すると、次の行が表示されます。
theResponse = webRequestObj.GetResponse();
WebException をスローします。
The remote server returned an error: (503) Server Unavailable.
すべてを try/catch ブロックにラップして例外を待つ代わりに、ウェブサイトが 503 エラーを返すかどうかを確認する方法はありますか? 毎秒多くの更新を行っているため、可能であれば try/catch を避けたいと考えています。