zoukankan      html  css  js  c++  java
  • C#判断网址是否可以访问

    /// <summary>
            /// 判断网址是否可以访问
            /// </summary>
            /// <param name="Url"></param>
            /// <returns></returns>
            protected static bool CheckPageUrl(string url)
            {
                bool result = false;
                try
                {
                    if (url.IndexOf("http").Equals(-1))
                    {
                        url = "http://" + url;
                         Console.WriteLine(url);
                    }
                    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                    myHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
                    myHttpWebRequest.Method = "GET";
                    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                    if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
                    {
                        result = true;
                    }
                    myHttpWebResponse.Close();
                }
                catch
                {
                    result = false;
                }

                return result;
            }

  • 相关阅读:
    Nginx配置文件说明
    http服务区域组网的一种方法
    InetAddress.getLocalHost()返回ip 地址异常听问题
    #!/bin/bash(转)
    ThreadPoolExecutor运转机制详解(转)
    memcache 入门学习资料
    Too many open files 异常
    Java并发编程之ConcurrentHashMap
    Java NIO 选择器(Selector)的内部实现(poll epoll)
    Python 的sub和replace的区别
  • 原文地址:https://www.cnblogs.com/zhipeng007/p/15136350.html
Copyright © 2011-2022 走看看