Fastest way to test internet connection

前端 未结 6 1680
别那么骄傲
别那么骄傲 2020-11-30 04:03

C# 2008 SP1

I am using this code to connect to our client website. This is for a softphone application. Before the user makes a call, the softphone has to test if th

6条回答
  •  死守一世寂寞
    2020-11-30 04:56

    request.GetResponse() itself will give you an exception if the host name can't be resolved, though, so you might want to put a try-catch around that, catch System.Net.WebException, and check its error status in the Status property. I'm not sure which statuses exactly would indicate no internet, though; most responses could just as well be due to dns or other connection problems.

提交回复
热议问题