• 检查URL、或者虚拟目录是否可以访问


            //检查虚拟目录是否可以访问
            public static bool Cmd(string cmdLine)
            {
                using (var process = new Process
                {
                    StartInfo =
                    {
                        FileName = "cmd.exe",
                        UseShellExecute = false,
                        RedirectStandardInput = true,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true,
                        RedirectStandardError = true
                    }
                })
                {
                    process.Start();
                    process.StandardInput.AutoFlush = true;
                    process.StandardInput.WriteLine(cmdLine);
                    process.StandardInput.WriteLine("exit");
    
                    Debug.WriteLine(process.StandardOutput.ReadToEnd());
    
                    String errorMessage = process.StandardError.ReadToEnd();
                    process.WaitForExit();
    
                    if (String.IsNullOrEmpty(errorMessage))
                    {
                        return true;
                    }
    
                    Debug.WriteLine(errorMessage);
                    return false;
                }
            }
            //检查链接是否可以访问
            public static bool CheckUrlVisit(string url)
            {
                try
                {
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                    if (resp.StatusCode == HttpStatusCode.OK)
                    {
                        resp.Close();
                        return true;
                    }
                }
                catch (WebException webex)
                {
                    return false;
                }
                return false;
            }
  • 相关阅读:
    常用的正则表达式,字符串,地址操作
    倒计时工具
    Java—集合框架List
    Java—包装类、Date和SimpleDateFormat、Calendar类
    Java—字符串
    Java —异常
    Java—多态
    Java—继承
    Java—封装
    Java —类和对象
  • 原文地址:https://www.cnblogs.com/ddhj/p/3080232.html
Copyright © 2020-2023  润新知