【问题标题】:ServicePointManager.ServerCertificateValidationCallback not being hitServicePointManager.ServerCertificateValidationCallback 未命中
【发布时间】:2012-12-07 23:34:00
【问题描述】:

我有以下代码。

public void Submit(string XML)
{
ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate;
TestWS.CW serv = new TestWS.CW();
string s = serv.Check(XML);
}

private static bool ValidateCertificate(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
}

但是,代码永远不会进入ValidateCertificate 方法....如果我提交标准HttpsWebRequest,但如果我使用网络服务,它就不起作用。我做错了什么?

【问题讨论】:

  • 即使是这样,您的 ValidateCertificate 方法也总是返回 true
  • 我知道,它应该总是返回 true。
  • 你解决了吗?

标签: c# servicepointmanager


【解决方案1】:

将此粘贴​​在您的启动代码中,以便在某处进行 HTTP 处理...

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

这对我有用,但我只对调试版本这样做...

【讨论】:

    猜你喜欢
    • 2020-04-20
    • 1970-01-01
    • 2015-01-29
    • 2014-12-10
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    相关资源
    最近更新 更多