c# - HttpWebResponse 返回 404 错误

标签 c# http-status-code-404 httpwebresponse

如何让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/

相关文章:

c# - 任务并行库 - 阻塞操作?

http - Golang net/http 文件服务器在 "/"以外的任何模式上给出 404

c# - C# 中的 Httpwebresponse 到 Httpresponsemessage

c# - 从 URL 获取图像但未完全加载

c# - 在不同的虚拟机上发送 C# worker

c# - 如何访问共享主机空间上的文件夹?

angular - Assets 未考虑基本 href url - 未找到错误

c# - 如果状态码不等于 200 OK,则使用 Polly 重试 api 请求

c# - 如何链接和应用外部 css 文件

asp.net-mvc - ASP.NET MVC : Controller. HandleUnknownAction 404 或 405?