I'm writing a .NET application which is supposed to post data to another .NET application. I use the following code to request the login page
WebProxy proxy = new WebProxy("http://proxy:80/", true);
HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
//proxy.Credentials = new NetworkCredential("myusername", "mypassword", "domain");
// webRequest.Proxy = proxy;
webRequest.Proxy = WebRequest.DefaultWebProxy;
StreamReader responseReader = new StreamReader
(webRequest.GetResponse().GetResponseStream());
string responseData = responseReader.ReadToEnd();
but it fails on this line
StreamReader responseReader = new StreamReader
(webRequest.GetResponse().GetResponseStream());
with the error message :
System.Net.WebException: The underlying connection was closed: The connection was
closed unexpectedly.
The underlying connection was closed: An unexpected error occurred on a send. This problem usually happens when the computer is using the Proxy/VPN. Please disable the Proxy/VPN temporary and try again.
The WebException class is thrown by classes descended from WebRequest and WebResponse that implement pluggable protocols for accessing the Internet. When WebException is thrown by a descendant of the WebRequest class, the Response property provides the Internet response to the application.
A message "underlying connection was closed the connection was closed unexpectedly" would commonly indicate that something in between your BDNA server and the download site has interrupted or disallowed the network connection. For example, network routing may not be allowing your BDNA server to access the Internet.
In my case, this solved the problem:
System.Net.ServicePointManager.Expect100Continue = false;
and none of the above.
Faced the same error for using http
GET for an API that used https
. Might be of help to someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With