接受VB.NET中的自签名TLS/SSL证书 [英] Accept self-signed TLS/SSL certificate in VB.NET
问题描述
我正在寻找一种使用VB.NET验证(或绕过验证)自签名SSL证书的方法.我在C#中找到了执行此操作的代码,并尝试将其转换为VB代码,但是我没有任何运气.
I'm searching for a way to validate (or bypass validation for) self-signed SSL certificates using VB.NET. I found code to do this in C# and tried converting it into VB code, but I'm not having any luck.
这是C#代码:这是我尝试过的:
Imports System
Imports System.Net
Imports System.Security.Cryptography.X509Certificates
Public Class clsSSL
Public Function AcceptAllCertifications(ByVal sender As Object, ByVal certification As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
Return True
End Function
End Class
然后在 WebRequest
之前,我有这行代码,这给了我一个错误.
Then before the WebRequest
I have this line of code which gives me an error.
ServicePointManager.ServerCertificateValidationCallback =
New System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications)
错误消息是:
委托'System.Net.Security.RemoteCertificateValidationCallback'要求使用"AddressOf"表达式或lambda表达式作为其构造函数的唯一参数.
Delegate 'System.Net.Security.RemoteCertificateValidationCallback' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.
推荐答案
在VB.Net中,您需要编写
In VB.Net, you need to write
ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications
这篇关于接受VB.NET中的自签名TLS/SSL证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!