如何在 C# 中等待和重复错误 Web 响应的 Web 响应?

how to wait and repeat web response for error web response in c#?

如何在 C# 中等待和重复错误 Web 响应的 Web 响应? 什么时候做 Web Response ,错误得到响应。我想尝试 web 响应没有错误并继续程序并成功获得响应 url。 我的代码:

 try
                {
                    HttpWebRequest URLp =(HttpWebRequest)WebRequest.Create(url);
                    URLp.Timeout = 190000;
                    URLp.Timeout = 260000;
                    URLp.ReadWriteTimeout = 260000;
                    using (WebResponse MyResponse1 = URLp.GetResponse())
                    {
                        str1 = new StreamReader(MyResponse1.GetResponseStream(), System.Text.Encoding.UTF8);
                        page1 = str1.ReadToEnd();
                    }
                }
                catch
                {
                    Thread.Sleep(70000);

                }

 StreamWriter stw1 = new StreamWriter(Address);
                stw1.Write(page1);
                stw1.Close();

你的意思是这样的?

 var success = false;
 while (!success)
 {
    try
                {
                    HttpWebRequest URLp =(HttpWebRequest)WebRequest.Create(url);
                    URLp.Timeout = 190000;
                    URLp.Timeout = 260000;
                    URLp.ReadWriteTimeout = 260000;
                    using (WebResponse MyResponse1 = URLp.GetResponse())
                    {
                        str1 = new StreamReader(MyResponse1.GetResponseStream(), System.Text.Encoding.UTF8);
                        page1 = str1.ReadToEnd();
                        success = true;
                    }
                }
                catch
                {
                    Thread.Sleep(70000);
                }

 }

StreamWriter stw1 = new StreamWriter(Address);
stw1.Write(page1);
stw1.Close();