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; } 

Closed due to the fact that off-topic party PashaPash 14 May '16 at 9:47 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Where does the program "stop running"? In the line shown by you - or all the same on the line request.GetResponse() ? - Pavel Mayorov
  • Is the host 168.213.3.106 pinged? Is there a proxy server on port 80 exactly? - Pavel Mayorov
  • one
    Maybe you just need to run it all in the stream? And in the course of execution of the thread to display the status of its implementation. - Vadim Pavlovich

1 answer 1

It seems that it was really not in the code, but in the host. Here are a couple of links to check: http://goldhous.com/programmirovanie/2012/01/17/ping-hosta-na-s.html http://s0m0m.ru/?p=566