I have seen a few other threads on this but haven't found a solution. When running my C# Windows From from debug mode, I am able to use the WebClient to read data from a web page. However, as soon as I create the executable for the application, I am unable to read the data from the web page. Here the exception that I am getting:
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
---End of inner exception stack trace ---
Here is a snippet of the code I am using:
WebClient webClient = new WebClient();
webClient.UseDefaultCredentials = true;
webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
string page = webClient.DownloadString(webPath + manPartNum);
Like I said previously, I am able to get this to work correctly in debug mode of visual studio but as soon as I create the executable, I am no longer able to read from the web page. Any help would be appreciated. What could be causing this issue?