我有以下密码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "HEAD";
request.Credentials = MyCredentialCache;
try
{
request.GetResponse();
}
catch
{
}
如何捕获特定的404错误?WebExceptionStatus.ProtocolError 只能检测到发生了错误,但不能给出错误的确切代码。
例如:
catch (WebException ex)
{
if (ex.Status != WebExceptionStatus.ProtocolError)
{
throw ex;
}
}
只是不够有用... 协议异常可能是401,503,403,任何东西。