我正在使用 VC 2008 并使用 .net 代码。我制作的 HttpWebRequest 客户端永远无法连接到使用不受信任证书的服务器(我制作了该证书,因此它是不受信任的)。错误是“TrustFailure”。
在C#中,我们可以做到
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
但是如何将其转换为 C++ 语法呢?
ServicePointManager::ServerCertificateValidationCallback = delegate { return true; };
// does not work
非常感谢!
最佳答案
我在我的类中定义了一个委托(delegate)方法并在构造函数中注册了它 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);
}
关于.net - 如何在 C++ 中使用 .net 自动接受无效的 SSL 连接证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5227686/