根据自签名证书的验证程序,远程证书无效

The remote certificate is invalid according to the validation procedure with self-signed certificate

我在本地开发机器上请求 URL 时收到错误消息`根据验证程序,远程证书无效。

我已经看了here

但我找不到此 C# 代码的 VB.NET 代码:

ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;

// Put this somewhere that is only once - like an initialization method
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate);
...

static bool ValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
   return true;
}

有人可以帮我翻译这段代码吗?我尝试了翻译器 converter.telerik.com 和 carlosag.net,但都失败了。

我们不只是翻译,而是先确定这一行的作用

 ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;

MSDN 文档说 ServerCertificateValidationCallback is a property of type RemoteCertificateValidationCallback

RemoteCertificateValidationCallback 是具有此签名的委托

'Declaration
Public Delegate Function RemoteCertificateValidationCallback ( _
    sender As Object, _
    certificate As X509Certificate, _
    chain As X509Chain, _
    sslPolicyErrors As SslPolicyErrors _
) As Boolean

(o, c, ch, er) => true; 是一个带有签名 RemoteCertificateValidationCallback 的 lamba 表达式,并且始终计算为真。

要在 VB.NET 中做同样的事情

ServicePointManager.ServerCertificateValidationCallback = Function(o,c,ch,er) (true)

This article will help第二部分你会吗,但思路是一样的。