Problems with WebRequest and Connection
-
This one has me stumped: I am using HttpWebRequest to resolve an external URL (that outputs an XML string). It works fine on my dev machine (W2K), and used to work on my production machine (W2K3). It seems that now, for some reason, the connection cannot be established. The error logged is: The underlying connection was closed: Unable to connect to the remote server." source="System" stack="at System.Net.HttpWebRequest.CheckFinalStatus()..." I can connect to the Internet via the browser on this machine, and all network related services seem to be working. (Terminal services, etc.) I've fiddled with the Timeout on the WebRequest object to no avail. The most frustrating thing is that it recently worked - once - then stopped working again. I'm not sure if it is a network issue, hardware issue, security issue on W2K3, etc.? Any help would be appreciated. Here is the function called: private string readHtmlPage(string url) { string _result; WebResponse objResponse; WebRequest objRequest = System.Net.HttpWebRequest.Create(url); objResponse = objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) ) { _result = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } return _result; } Thanks! - gsk. Just because I don't care, doesn't mean I don't understand. - Homer J. Simpson
-
This one has me stumped: I am using HttpWebRequest to resolve an external URL (that outputs an XML string). It works fine on my dev machine (W2K), and used to work on my production machine (W2K3). It seems that now, for some reason, the connection cannot be established. The error logged is: The underlying connection was closed: Unable to connect to the remote server." source="System" stack="at System.Net.HttpWebRequest.CheckFinalStatus()..." I can connect to the Internet via the browser on this machine, and all network related services seem to be working. (Terminal services, etc.) I've fiddled with the Timeout on the WebRequest object to no avail. The most frustrating thing is that it recently worked - once - then stopped working again. I'm not sure if it is a network issue, hardware issue, security issue on W2K3, etc.? Any help would be appreciated. Here is the function called: private string readHtmlPage(string url) { string _result; WebResponse objResponse; WebRequest objRequest = System.Net.HttpWebRequest.Create(url); objResponse = objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) ) { _result = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } return _result; } Thanks! - gsk. Just because I don't care, doesn't mean I don't understand. - Homer J. Simpson
Maybe a proxy problem ? If you use a proxy server to connect to the internet, try to set the Proxy member of WebRequest. example
private string readHtmlPage(string url)
{
string _result;
WebResponse objResponse;WebProxy myProxy = new WebProxy( <hostname/ip>, <port number> ); // if your proxy requires authentication add // myProxy.Credentials = new NetworkCredentials( <username>, <password> \[, <domain>\] ) WebRequest objRequest = System.Net.HttpWebRequest.Create(url); // apply proxy to web request objRequest.Proxy = myProxy; objResponse = objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) ) { \_result = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } return \_result;
}
Maybe this helps ;)
-
Maybe a proxy problem ? If you use a proxy server to connect to the internet, try to set the Proxy member of WebRequest. example
private string readHtmlPage(string url)
{
string _result;
WebResponse objResponse;WebProxy myProxy = new WebProxy( <hostname/ip>, <port number> ); // if your proxy requires authentication add // myProxy.Credentials = new NetworkCredentials( <username>, <password> \[, <domain>\] ) WebRequest objRequest = System.Net.HttpWebRequest.Create(url); // apply proxy to web request objRequest.Proxy = myProxy; objResponse = objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) ) { \_result = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } return \_result;
}
Maybe this helps ;)
An excellent suggestion, and I have saved your code in case of future problems. However, in this case, I have checked with the hosting providor and they have said that no proxy server is used for the connection. Any other ideas would be appreciated. Can anyone tell me what the WebRequest relies on for establishing a connection? I am assuming the local TCP/IP settings, DNS, etc., but is there anything else I may be missing? Just because I don't care, doesn't mean I don't understand. - Homer J. Simpson