Can't connect to https page
C#
1
Posts
1
Posters
0
Views
1
Watching
-
Hello, I'm trying to access an https page, I don't know why .NET doesn't allow it here is the error I got "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." and when I try to override ServicePointManager.ServerCertificateValidationCallback with this function
public static bool ValidateServerCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}I got time out exception. here is a snippet of my code
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate); CookieContainer c = new CookieContainer(); reqLogin = (HttpWebRequest)WebRequest.Create(url); reqLogin.Method = "POST"; reqLogin.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729)"; reqLogin.ContentType = "application/x-www-form-urlencoded"; reqLogin.KeepAlive = true; reqLogin.CookieContainer = new CookieContainer(); reqLogin.CookieContainer = c; //reqLogin.CookieContainer.Add(col1); reqLogin.AllowAutoRedirect = true; reqLogin.UseDefaultCredentials = true; reqLogin.Timeout = 5000; using (StreamWriter sendingData = new StreamWriter(reqLogin.GetRequestStream())) { sendingData.Write(postMessage); sendingData.Flush(); sendingData.Close(); } resLogin = (HttpWebResponse)reqLogin.GetResponse();
I'm sure that you faced that problem before, i'm searching about a solution for this problem from 4 hours and couldn't find any solution, I really hope that you can help me Thanks in Advance.