gpt4 book ai didi

.net - 在 VB.NET 中接受自签名 TLS/SSL 证书

转载 作者:太空宇宙 更新时间:2023-11-03 12:38:31 24 4
gpt4 key购买 nike

我正在寻找一种使用 VB.NET 验证(或绕过验证)自签名 SSL 证书的方法。我在 C# 中找到了执行此操作的代码,并尝试将其转换为 VB 代码,但我没有任何运气。

这是 C# 代码:How do I use WebRequest to access an SSL encrypted site using https?

这是我尝试过的:

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 之前我有这行代码,它给我一个错误。

ServicePointManager.ServerCertificateValidationCallback =
New System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications)

错误信息是:

Delegate 'System.Net.Security.RemoteCertificateValidationCallback' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.

最佳答案

在VB.Net中,你需要这样写

ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications

关于.net - 在 VB.NET 中接受自签名 TLS/SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5998004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com