请问关于WebRequest的如下两种写法的运行结果有何不同
====第1种写法:====
int i = 1;
while (true)
{
try
{
//访问本机IIS里的静态页面
WebRequest.Create("http://localhost/AutoRecovery/IISOK.htm").GetResponse();
Console.WriteLine(i + ": Success");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
i++;
Thread.Sleep(1000);
}
====第2种写法:====
int i = 1;
while (true)
{
try
{
//访问别的机器IIS里的静态页面
WebRequest.Create("http://othersMachine/AutoRecovery/IISOK.htm").GetResponse();
Console.WriteLine(i + ": Success");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
i++;
Thread.Sleep(1000);
}
[解决办法]
设置一个
webrequest.Timeout = 3000;
[解决办法]
把Timeout设长一点试一下
[解决办法]
int i = 1;
while (true)
{
try
{
//访问别的机器IIS里的静态页面
WebRequest MyResquest = WebRequest.Create("http://othersMachine/AutoRecovery/IISOK.htm");
MyResquest.Timeout = 10000;
Console.WriteLine(i + ": Success");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
i++;
Thread.Sleep(1000);
}