actually the question in the title of the topic. There is a code that sends a request using a proxy and there are exceptions in case of an error, and there is also a text file that contains replacement proxies, in case the used proxy is not working. The question is how do I download a new proxy and automatically send a request again, in case the current one is not working? Here is the code:
class Program { static void Main(string[] args) { try { var proxyClient = HttpProxyClient.Parse("183.207.228.7:8000"); var request = new HttpRequest(); request.UserAgent = HttpHelper.ChromeUserAgent(); request.Proxy = proxyClient; // Отправляем запрос. HttpResponse response = request.Get("http://2ip.ru/"); // Принимаем тело сообщения в виде строки. string content = response.ToString(); Console.WriteLine(content); File.WriteAllText("asd.txt", content); Console.Read(); } catch (HttpException ex) { Console.WriteLine("Произошла ошибка при работе с HTTP-сервером: {0}", ex.Message); switch (ex.Status) { case HttpExceptionStatus.Other: Console.WriteLine("Неизвестная ошибка");Console.Read(); break; case HttpExceptionStatus.ProtocolError: Console.WriteLine("Код состояния: {0}", (int)ex.HttpStatusCode);Console.Read(); break; case HttpExceptionStatus.ConnectFailure: Console.WriteLine("Не удалось соединиться с HTTP-сервером.");Console.Read(); break; case HttpExceptionStatus.SendFailure: Console.WriteLine("Не удалось отправить запрос HTTP-серверу.");Console.Read(); break; case HttpExceptionStatus.ReceiveFailure: Console.WriteLine("Не удалось загрузить ответ от HTTP-сервера.");Console.Read(); break; } } } } I use xNet library.