首页 > 代码库 > C# 判断网站是不是discuz论坛

C# 判断网站是不是discuz论坛

 

if (this.txturl.Text == "")
            {
                this.lblmess.Text = "请输入网址";
            }
            else
            {
                GetHttp getHttp = new GetHttp();
                string url = "http://" + this.txturl.Text + "/uc_server/control/admin/db.php";
                try
                {
                    string httpWebRequest = getHttp.GetHttpWebRequest(url);
                    if (httpWebRequest.Contains("Access"))
                    {
                        this.lblmess.Text = "Discuz论坛程序!";
                    }
                    else
                    {
                        this.lblmess.Text = "非论坛";
                    }
                }
                catch (WebException)
                {
                    MessageBox.Show("域名输入错误!");
                }

 

public string GetHttpWebRequest(string url)
        {
            Uri requestUri = new Uri(url);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri);
            httpWebRequest.UserAgent = "User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705";
            httpWebRequest.Accept = "*/*";
            httpWebRequest.KeepAlive = true;
            httpWebRequest.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            Stream responseStream = httpWebResponse.GetResponseStream();
            StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
            string result = streamReader.ReadToEnd();
            streamReader.Close();
            responseStream.Close();
            httpWebResponse.Close();
            return result;
        }

 

C# 判断网站是不是discuz论坛