网络故障后,GetResponseStream无法恢复

时间:2014-10-31 21:03:23

标签: c# http httpwebrequest

我正在尝试编写一个从本地Web服务器接收数据的弹性应用程序。读取数据的代码如下:

     var myRequest =
           (HttpWebRequest)
                WebRequest.Create(
                     "http://"+_ipAddress+
                     "/FileBrowser/Download?Path=/DataLogs/DataLogSmall.csv&RAW");

      myRequest.Referer = "http://"+_ipAddress+"/Portal/Portal.mwsl?PriNav=FileBrowser";
      var myHttpWebResponse = (HttpWebResponse) myRequest.GetResponse();
      // Display the contents of the page to the console.
      Stream streamResponse = myHttpWebResponse.GetResponseStream();

此代码由try / catch块包围。如果在程序运行时拔掉路由器,则会引发以下错误:

System.Net.WebExceptionL The request was aborted: The operation has timed out.

这个有道理,我拔掉了路由器上的插头。

System.Net.WebException: Unable to connect to the remote server

拔出路由器时,上述错误仍在继续。

System.Data.Entity.Core.EntityException: The underlying provider failed on Open.

当路由器重新上线时会发生此(上面)错误。它通常发生一次或两次

System.Net.WebException: The operation has timed out

此错误会永远重复。

如果我停止并启动该程序,它将完美运行。 有什么想法吗?

0 个答案:

没有答案
相关问题