gpt4 book ai didi

.net - 底层连接已关闭 : Could not establish trust relationship for the SSL/TLS secure channel

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

这是我的代码,我花了很长时间才写出来,因为我还是个 nube:

Imports System.Net
Imports System.Text
Imports System.IO

Public Class Form1

Dim logincookie As CookieContainer

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Dim postdata As String = "action=do_login&url=https%3A%2F%2Fforum.suprbay.org% 2F&quick_login=1&quick_username=USERNAME&quick_password=PASSWORD&submit=Login&quick_remember=yes"
Dim tempcookies As New CookieContainer
Dim encoding As New UTF8Encoding
Dim bytedata As Byte() = encoding.GetBytes(postdata)
Dim postreq As HttpWebRequest = DirectCast(WebRequest.Create("https://forum.suprbay.org/member.php"), HttpWebRequest)

postreq.Method = "POST"
postreq.KeepAlive = True
postreq.CookieContainer = tempcookies
postreq.ContentType = "application/x-www-forum-urlencoded"
postreq.Referer = "https://forum.suprbay.org/member.php"
postreq.UserAgent = "Mozilla/5.0 (Windows NT 6.2; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"
postreq.ContentLength = bytedata.Length

Dim postreqstream As Stream = postreq.GetRequestStream()
postreqstream.Write(bytedata, 0, bytedata.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postreq.GetResponse(), HttpWebResponse)

tempcookies.Add(postresponse.Cookies)
logincookie = tempcookies

Dim postreqreader As New StreamReader(postresponse.GetResponseStream)
Dim thepage As String = postreqreader.ReadToEnd

RichTextBox1.Text = thepage

End Sub

End Class

当我运行它并单击按钮时,出现以下错误:

"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

这是 PirateBay.Se 的官方论坛,它是一个种子下载网站,如果您在常规浏览器中访问它,您会收到有关信任证书的警告,所以这可能就是我收到错误的原因,对吧?我怎样才能忽略信任证书和其他东西,以便我的应用程序可以正常工作?

最佳答案

此行应忽略连接上的信任错误,在尝试连接之前执行此操作:

ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateRemoteCertificate

你还需要在你的类中定义它:

   Public Shared Function ValidateRemoteCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
Return True
End Function

抱歉,如果这不是对 VB.Net 的完美翻译,我最初是用 C# 编写的。

编辑:

是的,这正是您收到此错误的原因,他们拥有的证书已过期。

关于.net - 底层连接已关闭 : Could not establish trust relationship for the SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11891529/

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