.NET Framework Developer Center >
.NET Development Forums
>
.NET Framework Networking and Communication
>
SSL: "An existing connection was forcibly closed by the remote host."
SSL: "An existing connection was forcibly closed by the remote host."
- Hello,
I'm trying to do a secure connect to the site https://212.77.100.18/p/ with .net 2.0 HttpWebRequest class,
unfortunately for some reason I'm not able to do that - WebException is thrown with inner exception message of "An existing connection was forcibly closed by the remote host."
I hoped I'll solve my problem with RemoteCertificateValidationCallback delegate which always returns "true", but it isn't called at all for this site (but works for other sites which needs manual acceptance of certificate).
The HttpWebResponse should return "403 Forbidden" as in Internet Explorer.
Can you help me, please?
//my code below
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://212.77.100.18/p/");
req.Method = "GET";
req.AllowAutoRedirect = false;
req.CookieContainer = new CookieContainer();
req.KeepAlive = true;
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727)";
req.ContentType = "application/x-www-form-urlencoded";
req.Accept = "*/*";
/*
I have also tried this: req.ClientCertificates.Add(X509Certificate.CreateFromCertFile("chris.cer"));
*/
using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
{
//not reached
}
public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
Answers
For this particular server you'll have to set the protocol to ssl3.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
I verified this fixes your problem and you will now get the 403 error as expected. The problem is a server problem, it drops the connection when we are trying to negotiate the ssl connection.
Let me know if this helped
Mariya
- yes! thank you very much

<bucket of roses>
All Replies
- anybody can help?
- I will look into this tomorrow morning and let you know what I find
For this particular server you'll have to set the protocol to ssl3.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
I verified this fixes your problem and you will now get the 403 error as expected. The problem is a server problem, it drops the connection when we are trying to negotiate the ssl connection.
Let me know if this helped
Mariya
- yes! thank you very much

<bucket of roses>


