T
TJO
Why do I keep getting the following error.
"The underlying connection was closed: Could not establish secure channel
for SSL/TLS."
I am trying to log into a SSL site with the following code. What am i
missing??
// Post Credentials
string postData = "uid=myuserid&currpassword=mypassword";
StreamWriter myWriter = null;
WebResponse objResponse2;
WebRequest objRequest2 = System.Net.HttpWebRequest.Create(cmbo_uri.Text);
objRequest2.Method = "POST";
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "application/x-www-form-urlencoded";
objRequest2.Timeout = 100000;
ServicePointManager.CertificatePolicy= new AcceptAllCertificatePolicy();
try
{
myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
}
catch (Exception e2)
{
txt_errormsg.Text = "Error Writing Request: " + e2.Message;
}
finally
{
if(myWriter != null)
myWriter.Close();
}
try
{
objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
using (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: " + re.Message;
}
sealed class AcceptAllCertificatePolicy : ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
//
// TODO: Add constructor logic here
//
}
public bool CheckValidationResult(ServicePoint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProblem)
{
// Just accept.
return true;
}
}
"The underlying connection was closed: Could not establish secure channel
for SSL/TLS."
I am trying to log into a SSL site with the following code. What am i
missing??
// Post Credentials
string postData = "uid=myuserid&currpassword=mypassword";
StreamWriter myWriter = null;
WebResponse objResponse2;
WebRequest objRequest2 = System.Net.HttpWebRequest.Create(cmbo_uri.Text);
objRequest2.Method = "POST";
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "application/x-www-form-urlencoded";
objRequest2.Timeout = 100000;
ServicePointManager.CertificatePolicy= new AcceptAllCertificatePolicy();
try
{
myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
}
catch (Exception e2)
{
txt_errormsg.Text = "Error Writing Request: " + e2.Message;
}
finally
{
if(myWriter != null)
myWriter.Close();
}
try
{
objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
using (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: " + re.Message;
}
sealed class AcceptAllCertificatePolicy : ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
//
// TODO: Add constructor logic here
//
}
public bool CheckValidationResult(ServicePoint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProblem)
{
// Just accept.
return true;
}
}