WebClient.DownloadString(url) when this url returns a 404 page, how can i skip this?

前端 未结 2 973
渐次进展
渐次进展 2020-12-10 09:41

I\'m using WebClient.DownloadString(url) to download a web page, when a url a 404 web page it stops and doesn\'t work anymore. I want to skip these pages when I got this fau

2条回答
  •  旧时难觅i
    2020-12-10 09:56

    You can put your code in a Try...Catch block and catch a WebException. If you want more control on how to handle specific errors, you can use the WebException's Status property which returns a WebExceptionStatus enumeration.

提交回复
热议问题