在C#控制台应用程序中,我需要捕获“无法显示网页”的输出,然后我就可以进行检查。如果浏览器打开了URL,那么意味着有互联网连接,否则连接断开。我正在使用以下代码。
请查看捕获输出的方法。
WebClient client = new WebClient();
string value = client.DownloadString("http://foo.com");
Console.WriteLine(value.Length);
Console.WriteLine(value);
Console.WriteLine("Press any key to continue");
Console.ReadKey(true);
请查看捕获输出的方法。