在C#中打开Web浏览器并捕获输出

Soh*_*ail 2 c#

从C#控制台应用程序我需要打开Web浏览器,我想要输出.这是链接中的服务器名称.如果Internet Explorer没有显示任何内容,则表示服务器已启动.如果我得到Internet Explorer无法显示网页,那么这意味着服务器已关闭.

下面是打开IE的代码

    Process.Start("https://foo.com");
Run Code Online (Sandbox Code Playgroud)

如果Internet Explorer显示一个空页面,那么服务器将关闭服务器.

并想知道浏览器如何自动关闭?

spe*_*der 6

using(WebClient client = new WebClient())
{
    string pageData;
    try
    {
        pageData = client.DownloadString(yourAddress);
    }
    catch(Exception e)
    {
        //something went wrong. Maybe the site is down?
    }
    //does pageData have expected content?
}
Run Code Online (Sandbox Code Playgroud)