本文介绍了HttpWebResponse返回404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让Httpwebresponse忽略404错误并继续吗?这比寻找输入例外是非常罕见的,当这种情况发生更容易。
How to let Httpwebresponse ignore the 404 error and continue with it? It's easier than looking for exceptions in input as it is very rare when this happens.
推荐答案
我假设你在code像有一个行的地方:
I'm assuming you have a line somewhere in your code like:
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
只要这种替代它:
Simply replace it with this:
HttpWebResponse response;
try
{
response = request.GetResponse() as HttpWebResponse;
}
catch (WebException ex)
{
response = ex.Response as HttpWebResponse;
}
这篇关于HttpWebResponse返回404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!