Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何监控网站中的更改?_C#_Web_Httpwebrequest_Monitoring_Httpwebresponse - Fatal编程技术网

C# 如何监控网站中的更改?

C# 如何监控网站中的更改?,c#,web,httpwebrequest,monitoring,httpwebresponse,C#,Web,Httpwebrequest,Monitoring,Httpwebresponse,因此,我已经为此工作了一个月,但我在网上什么也没发现,所以我认为可以每分钟检查网站源代码的更改,但似乎它的源代码每秒钟都在更改,所以我的编码中是否有任何问题,或者是否有其他方法来监控网站的更改 这是我的密码: private void Startbtn_Click(object sender, EventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com")

因此,我已经为此工作了一个月,但我在网上什么也没发现,所以我认为可以每分钟检查网站源代码的更改,但似乎它的源代码每秒钟都在更改,所以我的编码中是否有任何问题,或者是否有其他方法来监控网站的更改

这是我的密码:

private void Startbtn_Click(object sender, EventArgs e)
   {

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");                            
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader source = new StreamReader(response.GetResponseStream());
richTextBox1.Text = source.ReadToEnd();
timer1.Start();
timer1.Interval = 60000;

     }

private void timer1_Tick(object sender, EventArgs e)
    {

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        StreamReader source2 = new StreamReader(response.GetResponseStream());
        RichTextBox checker = new RichTextBox();
        checker.Text = source2.ReadToEnd();
        if (richTextBox1.Text == "")
        {
            richTextBox1.Text = checker.Text;

        }
        else
        {


            if (richTextBox1.Text != checker.Text)
            {
                MessageBox.Show("somthing changed");
                richTextBox1.Text = checker.Text;
            }
            else
            {
                MessageBox.Show("No changes yet!");

            }
        }
    }

您已将计时器间隔设置为5000毫秒,使其仅为5秒。因此,您的代码将每5秒运行一次。如果您想每分钟运行一次计时器,则应将其设置为1000x60=60000毫秒。我希望这会有所帮助

首先,我建议您在需要将页面的实际内容与存储版本进行比较时:

  • 将您存储的MD5哈希与新的哈希进行比较(不是每次都比较内容)
  • 请记住,页面中有一些变化的元素,您可能不认为这些元素是页面内容的变化

  • 一些服务器会返回一个
    上次修改的
    标题,我想你可以用它来做一个比较。

    我知道时间间隔,这只是一个例子,但感谢我将更改它,以避免更多关于计时器的问题,重点是它总是在网站源代码中找到更改!我懂了。你的意思是实际内容每秒钟都在变化。事实上,如果您看到上述请求返回的响应,那么会有大量数据,并且每个请求都会发生任何变化。据我所知,事实上,每个请求和响应都是独一无二的。因此,通过这种方式,每个请求的响应都是唯一的。关键是,你需要澄清你到底想要比较哪一部分,然后从响应中筛选出那一部分,然后进行比较。但对于这一点,您首先必须详细研究“Respose”,并了解每个请求的具体变化。