2011-03-08 42 views
3

我正在使用VC 2008并使用.net代码。我所做的HttpWebRequest客户端永远不能连接到使用不可信证书的服务器(我制作了该证书,因此它不受信任)。错误是“TrustFailure”。如何在C++中使用.net自动接受SSL连接的无效证书?

在C#中,我们可以做

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; 

但如何将其转换成C++的语法?

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

非常感谢!

回答

1

我知道这可能不是你正在寻找的答案,但你不能编写处理这个问题的C#方法,只是从你的C++代码中调用它?

2

我在类中定义的委托方法,并在构造函数中注册它 系统::网:: 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); 
}