如何让 Httpwebresponse 忽略 404 错误并继续它?这比在输入中查找异常更容易,因为这种情况发生时非常罕见。

最佳答案

我假设您的代码中某处有一行,例如:

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

只需将其替换为:
HttpWebResponse response;

try
{
    response = request.GetResponse() as HttpWebResponse;
}
catch (WebException ex)
{
    response = ex.Response as HttpWebResponse;
}

关于c# - HttpWebResponse 返回 404 错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1857512/

10-10 19:59