DidIReallyWriteThat
DidIReallyWriteThat

Reputation: 1033

Connection timed out when going through proxy

This code works perfectly when not going through a proxy server. it loads the required webpage. When i uncomment one line I get an error.

Error message

"The underlying connection was closed: The connection was closed unexpectedly."   
System.Exception
System.Net.WebException

The one line that causes the error.

//request.Proxy = new Webproxy("192.157.252.245",80);

The proxy I am using works fine when going through a proxy website or setting it as local proxy.

Uri address = new Uri("http://google.com/");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";

////////Add Proxy
//request.Proxy = new Webproxy("192.157.252.245",80);
////////End Add Proxy

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
    StreamReader streamReader = new StreamReader(response.GetResponseStream());
    string strReaderXML = streamReader.ReadToEnd();
}

Upvotes: 0

Views: 7108

Answers (1)

Dhruv
Dhruv

Reputation: 89

First of all do one layman check, because sometime IP is not reachable or port is not open to receive connection, may be firewall don't allow your connection.

Kindly visit below links, which could help you to solve your problem:

  1. System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly
  2. The underlying connection was closed: The connection was closed unexpectedly

Upvotes: 1

Related Questions