Bajinder

Bajinder

  • NA
  • 9
  • 7.6k

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

Mar 30 2007 6:59 AM
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:

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 

Answers (2)