I found that HttpWebRequest throws a WebException for non-existing resources. It seems very strange to me, because HttpWebResponse has the StatusCode property (the NotFount element exists). Do you think this has any reason for this, or maybe it's just a developers problem?
var req = (HttpWebRequest)WebRequest.Create(someUrl);
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse()) {
if (response.StatusCode == HttpStatusCode.OK) { ...}
}
Danil source
share