我收到错误`在本地开发机器上请求URL时,根据验证程序,远程证书无效。
我已经看过here。
但是我无法找到这个C#代码的VB.NET代码:
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
OR
// 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,但那些失败了。
答案 0 :(得分:1)
而不是仅仅翻译让我们首先确定这条线的作用
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
MSDN文档说ServerCertificateValidationCallback是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表达式,并且始终计算为true。
在VB.NET中做同样的事情
ServicePointManager.ServerCertificateValidationCallback = Function(o,c,ch,er) (true)
第二部分是This article will help,但这是相同的想法。