Skip to content

The underlying connection was closed: Unable to connect to the remote server.

Bajinder

Asked Mar 30, 2007, 2:59 AM EDT2 answers
Share
LinkedInX
I getting this error:The underlying connection was closed: Unable to connect to the remote server on the remote server when tried to get response of a webpage.On local its working fine

Here is the Code:

C#
private string HttpContent( string url )
{



String result="";
try
{
HttpWebResponse objResponse;
HttpWebRequest objRequest = ((HttpWebRequest) (WebRequest.Create(url)));
objRequest.Method ="GET";
objRequest.Timeout = 90000;
objRequest.KeepAlive = false;
objRequest.ProtocolVersion=HttpVersion.Version10;
ServicePointManager.Expect100Continue =false;
objRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040707 Firefox/0.9.2";

//objRequest.Accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";

//objRequest.ContentType = @"application/x-www-form-urlencoded";
//IWebProxy proxyObject =
//new WebProxy("http://localhost:8099", false);
//objRequest.Proxy=proxyObject;
//objRequest.Proxy=GlobalProxySelection.GetEmptyWebProxy();

//objRequest.Proxy = WebProxy.GetDefaultProxy();
//objRequest.Proxy.Credentials = CredentialCache.DefaultCredentials;
//objRequest.AllowAutoRedirect=true;
//objRequest.MaximumAutomaticRedirections=10;
//objRequest.Timeout=(int) new TimeSpan(0,1,0).TotalMilliseconds;
//objRequest.UserAgent="Mozilla/3.0 (compatible; My Browser/1.0)";
objResponse = ((HttpWebResponse) (objRequest.GetResponse()));
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
result=result.Replace("javascript: window.print()","");
result=result.Replace("../Images/newsletter","http://www.nadp.org/images/newsletter");

// Close and clean up the StreamReader

sr.Close();
}

objResponse.Close();

}
catch(Exception ex)
{
Response.Write(ex.Message.ToString());
}



return result;
}
Thanks In Advance 

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hello.
    Check out in your web.config file whether you have any web service which is running on a different sytem and make sure that the system is not shut down. And also ensure that remote service URL of the machine it is pointing to is not shut down.
    this should solve your problem...
    0
  • 0
    Error is still there.No body in this world able solve this Error?
    0