我得到了这段代码,它试图捕获 410 代码,但它在第一行抛出错误并且没有通过其余代码,
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.Gone)
{
有什么方法可以捕获除上述之外的 410 代码。
在下面的答案的帮助下回答代码
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
if (((HttpWebResponse)(ex.Response)).StatusCode == HttpStatusCode.NotFound || ((HttpWebResponse)(ex.Response)).StatusCode == HttpStatusCode.Gone)
{