Just tested.
I got the exception as well, on 2.10...
But it works like this:
Code:
using System;
using System.Security.Cryptography.X509Certificates;
namespace SSLtest
{
class MainClass
{
// callback used to validate the certificate in an SSL conversation
private static bool ValidateRemoteCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
System.Net.Security.SslPolicyErrors policyErrors
)
{
return true;
/*
if (Convert.ToBoolean(ConfigurationManager.AppSettings["IgnoreSslErrors"]))
{
// allow any old dodgy certificate...
return true;
}
else
{
return policyErrors == SslPolicyErrors.None;
}
*/
} // End Function ValidateRemoteCertificate
public static void Main (string[] args)
{
//System.Net.ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
System.Net.ServicePointManager.ServerCertificateValidationCallback += (s,ce,ca,p) => true;
string strResponse = null;
try
{
System.Net.WebRequest request = System.Net.HttpWebRequest.Create("https://encrypted.google.com/");
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse) request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(stream);
strResponse = sr.ReadToEnd();
sr.Close();
sr.Dispose();
stream.Dispose();
}
catch(System.IO.IOException ex)
{
Console.WriteLine("Failed to connect to URI");
Console.WriteLine("Reason:");
Console.WriteLine(ex.Message);
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Stacktrace:");
Console.WriteLine(ex.StackTrace);
}
catch(System.UriFormatException ex)
{
Console.WriteLine("Bad URI format");
Console.WriteLine("Reason:");
Console.WriteLine(ex.Message);
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Stacktrace:");
Console.WriteLine(ex.StackTrace);
}
Console.WriteLine ("Read the following stream:");
Console.WriteLine(strResponse);
Console.WriteLine(Environment.NewLine);
Console.WriteLine(" --- Press any key to continue --- ");
Console.ReadKey();
} // End Sub Main
} // End Class MainClass
} // End Namespace SSLtest
As a sidenote:
Code:
System.Net.ServicePointManager.ServerCertificateValidationCallback = () => true;
doesn't compile. Bad advice.
I don't know whether this is the same on Windows, I just know that the VB.NET version works on Windows, and that I used the developer fusion web-service to translate the VB.NET piece to C#.
But it works like this:
Code:
System.Net.ServicePointManager.ServerCertificateValidationCallback += (s,ce,ca,p) => true;
Bookmarks