Почему вместо одного запроса выполняется два - C#
Формулировка задачи:
Листинг программы
- public string Get(string url, CookieContainer cookieCollection=null, bool Redirect = true)
- {
- string str = "error";
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = "GET";
- request.Headers.Add("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4");
- request.UserAgent = UserAgent;
- request.Timeout = Time;
- request.CookieContainer = cookieCollection;
- request.KeepAlive = true;
- request.AllowAutoRedirect = Redirect;
- if (ProxyHTTP != null)
- {
- try
- {
- string[] strArray = ProxyHTTP.Split(new [] { ':' });
- request.Proxy = new WebProxy(strArray[0], Convert.ToInt32(strArray[1]));
- }
- catch
- {
- MessageBox.Show("Неверные прокси");
- }
- }
- using (Stream stream = request.GetResponse().GetResponseStream())
- {
- try
- {
- this.cookieCollection = request.CookieContainer;
- }
- catch
- {
- }
- str = new StreamReader(stream, Encoding.UTF8).ReadToEnd();
- }
- AbsoluteUri = request.Address.AbsoluteUri;
- }
- catch
- {
- }
- return str;
- }
Решение задачи: «Почему вместо одного запроса выполняется два»
textual
Листинг программы
- var web = new web();
- var coooo = new CookieContainer();
- web.UserAgent=HttpHelper.RandomChromeUserAgent();
- web.ProxyHTTP = "41.75.201.146:8080";
- web.Get("https://vk.com/",coooo);
- MessageBox.Show(web.Loc);
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д