2

I have a next problem: when I try to create a HttpWebRequest with proxy, I get a WebException with the message

The underlying connection was closed: The connection was closed unexpectedly.

What I am doing wrong?

Here is my code:

    var webRequest = (HttpWebRequest)WebRequest.Create(@"http://msdn.microsoft.com/");

    webRequest.Proxy = new WebProxy("109.254.143.7", 1080);
    webRequest.KeepAlive = false;
    //webRequest.ProtocolVersion = HttpVersion.Version10;

    var myResponse = (HttpWebResponse)webRequest.GetResponse();
    var stream = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
    var text = stream.ReadToEnd();

P.S.: It happens only when I try to use the proxy.

Thanks in advance!

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • 1
    Well, it looks like the proxy is closing the connection, just as the exception indicates. Are you sure it _is_ an HTTP proxy and that you're allowed to use it? – CodeCaster Jan 10 '16 at 14:44
  • 1
    oh, I really didn't notice, that I'm using a SOCKS proxy, thanks! :) But some HTTP proxies throws me an other errors, like: "The underlying connection was closed: An unexpected error occurred on a receive." and "The remote server returned an error: (400) Bad Request" – Nick Nikitin Jan 10 '16 at 19:26

0 Answers0