好吧,这个问题几乎解释了它。我知道在 String.equals 期间代码很脏,但我只是想看看我是否理解标题响应。显然我没有,因为我在浏览器中观看,当添加新问题时,我的程序从不输出“是的,它改变了”为什么会这样?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using System.Net;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Uri myUri = new Uri("http://stackoverflow.com/questions?sort=newest");
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
string org = myHttpWebResponse.Headers.GetValues("Date")[0];
string newone = "";
while (true) //STRICTING FOR TESTING. THIS WOULD BE A Dos ATTACK AS IT NEVER HAS A DELAY BETWEEN REQUESTS.
{
myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
newone = myHttpWebResponse.Headers.GetValues("Date")[0];
if (!newone.Equals(org))
break;
}
Console.WriteLine("Yep it changed");
Console.ReadLine();
}
}
}