T
TJO
I cannot post login user name and password data to an SSL web form without
the following error.
"The underlying connection was closed: Could not establish secure channel
for SSL/TLS."
I have looked hi and low for the reason why but each time i try something
different i get the same error. It also appears that this problem has been
posted numerous time without a complete answer. MS PLEASE HELP HERE.
I don't know if this is correct but I have created mycert.cer by going into
the Certification Manager MMC and exporting the cert from this particular
site. (Specific help in creating the cer file would be greatly appreciated
also. )
postData = "uid=myuserid&currpassword=mypassword";
objRequest2 =
(HttpWebRequest)System.Net.HttpWebRequest.Create(cmbo_uri.Text);
objRequest2.Method = "POST";
objRequest2.AllowAutoRedirect = true;
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "application/x-www-form-urlencoded";
objRequest2.Timeout = 100000;
objRequest2.CookieContainer = new CookieContainer();
objRequest2.AllowWriteStreamBuffering = true;
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
X509Certificate x509 = X509Certificate.CreateFromCertFile
(@"C:\mycert.cer");
objRequest2.ClientCertificates.Add(x509);
try
{
myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
txt_header.Text = "Sent Request Stream\n " + postData;
}
catch (Exception e2)
{
txt_errormsg.Text = "Error Writing Request: " + e2.Message + "\n" +
e2.ToString();
}
finally
{
if(myWriter != null)
myWriter.Close();
}
try
{
objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
StreamReader sr = new StreamReader(objResponse2.GetResponseStream());
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
txt_header.Text = objResponse2.Headers.ToString();
txt_response.Text = result;
}
catch (Exception re)
{
txt_errormsg.Text = "Error Getting Response: " + "\n" + re.ToString();
}
}
sealed class AcceptAllCertificatePolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProblem)
{
// Just accept.
return true;
}
}
the following error.
"The underlying connection was closed: Could not establish secure channel
for SSL/TLS."
I have looked hi and low for the reason why but each time i try something
different i get the same error. It also appears that this problem has been
posted numerous time without a complete answer. MS PLEASE HELP HERE.
I don't know if this is correct but I have created mycert.cer by going into
the Certification Manager MMC and exporting the cert from this particular
site. (Specific help in creating the cer file would be greatly appreciated
also. )
postData = "uid=myuserid&currpassword=mypassword";
objRequest2 =
(HttpWebRequest)System.Net.HttpWebRequest.Create(cmbo_uri.Text);
objRequest2.Method = "POST";
objRequest2.AllowAutoRedirect = true;
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "application/x-www-form-urlencoded";
objRequest2.Timeout = 100000;
objRequest2.CookieContainer = new CookieContainer();
objRequest2.AllowWriteStreamBuffering = true;
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
X509Certificate x509 = X509Certificate.CreateFromCertFile
(@"C:\mycert.cer");
objRequest2.ClientCertificates.Add(x509);
try
{
myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
txt_header.Text = "Sent Request Stream\n " + postData;
}
catch (Exception e2)
{
txt_errormsg.Text = "Error Writing Request: " + e2.Message + "\n" +
e2.ToString();
}
finally
{
if(myWriter != null)
myWriter.Close();
}
try
{
objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
StreamReader sr = new StreamReader(objResponse2.GetResponseStream());
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
txt_header.Text = objResponse2.Headers.ToString();
txt_response.Text = result;
}
catch (Exception re)
{
txt_errormsg.Text = "Error Getting Response: " + "\n" + re.ToString();
}
}
sealed class AcceptAllCertificatePolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProblem)
{
// Just accept.
return true;
}
}