Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problems with WebRequest and Connection

Problems with WebRequest and Connection

Scheduled Pinned Locked Moved ASP.NET
helpsysadmincsharphardwaredata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Geoff Kushnir
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • G Geoff Kushnir

      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

      K Offline
      K Offline
      Klaus Weisser
      wrote on last edited by
      #2

      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 ;)

      G 1 Reply Last reply
      0
      • K Klaus Weisser

        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 ;)

        G Offline
        G Offline
        Geoff Kushnir
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups