How to accept invalid SSL connection certificate automatically using .net in C ++?

I am using VC 2008 and using .net codes. The HttpWebRequest client that I made can never connect to a server that uses an untrusted certificate (I created this certificate, so it is not trusted). Error: "TrustFailure".

In C # we can do

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

But how to convert this to C ++ syntax?

ServicePointManager::ServerCertificateValidationCallback = delegate { return true; };
// does not work

Many thanks!

+3
source share
2 answers

I defined a delegate method in my class and registered it in the constructor for System :: Net :: ServicePointManager :: ServerCertificateValidationCallback

bool CMyClass::AcceptingCertificate(System::Object^ rObjectSender, X509Certificate^ rX509Certificate, X509Chain^ rX509Chain , SslPolicyErrors rErrors)
{
  return true;
}

CMyClass::CMyClass(void)
{
  System::Net::ServicePointManager::ServerCertificateValidationCallback = gcnew RemoteCertificateValidationCallback(&CMyClass::AcceptingCertificate);
}
+2
source

, , , , , #, ++?

+1

All Articles