我正在扫描具有多条路径示例的单个网址:http://url.com/path1
至1000
。有时候,我得到一个WebException
但在我catch
块,它会抛出一个NullReferenceException
错误,如果我不使用行
if (x.Status == WebExceptionStatus.ProtocolError && x.Response != null)
WebException响应属性返回null
所以我的问题是:有没有下面的代码修复错误或只是忽略它?
错误没有一个特定的路径错误只是随机像http://url.com/path10
或任何其他链接谢谢:)
catch (WebException x)
{
if (x.Status == WebExceptionStatus.ProtocolError && x.Response != null)
{
HttpWebResponse response = (HttpWebResponse)x.Response;
if (response.StatusCode == HttpStatusCode.NotFound)
{
listBox3.Items.add(listBox1.Items[i].ToString());
}
}
}
哪一部分你不明白? – terrala7
我正在用很多路径扫描1个url:http://url.com/path1到1000,但是如果我不使用if(x.Status == WebExceptionStatus.ProtocolError && x.Response!= null) '它会抛出'NullReferenceException'错误,所以是上面的代码修复错误或只是忽略它:) – terrala7
我也不明白这个问题。我认为你需要改写它,因为你的英语不太好。此时不需要反对票。试着澄清它,让我们知道你到底想要什么。编辑问题,不要写额外的评论。 –