I compose a parser as an educational task, and everything works fine until I add the WebProxy object, here are 2 lines of code:
WebProxy wp = new WebProxy("168.213.3.106", 80); request.Proxy = wp;
the program tightly gets up (does not freeze, but seems to stop executing). What to do?!
The whole method:
public static string DownloadHtml(string uri, Encoding encoding) { HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest; WebProxy wp = new WebProxy("168.213.3.106", 80); request.Proxy = wp; request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.KeepAlive = true; // получаем ответ HttpWebResponse response = request.GetResponse() as HttpWebResponse; // поток данных получаемых с сервера StreamReader sr = new StreamReader(response.GetResponseStream(), encoding); sr.ReadLine(); string html = sr.ReadToEnd(); return html; }
request.GetResponse()
? - Pavel Mayorov