gpt4 book ai didi

VB.Net Web Scraper - 请求被中止 : Could not create SSL/TLS secure channel

转载 作者:行者123 更新时间:2023-12-04 22:42:09 24 4
gpt4 key购买 nike

我正在开发一个网络抓取程序,在禁用 Tls 1.0 和 1.1 并启用 Tls 1.2 和 1.3 的网站上出现以下错误:
'请求被中止:无法创建 SSL/TLS 安全通道'
我还应该注意,我使用的是 .Net 4.8 版
这是我用来检查的网站:
https://www.cdn77.com/tls-test
我已经阅读了近十几篇关于该主题的帖子,但没有一个解决方案对我有用。
这是代码。它适用于大多数网站:

        Try
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or
SecurityProtocolType.Tls13

Dim address = New Uri(url)

Using client = New WebClient()
Dim stream = client.OpenRead(address) ' This is where exception is caught
Using sr = New StreamReader(stream)
Dim page = sr.ReadToEnd()
Return page
End Using
End Using

Catch ex As Exception
Return ex.Message
End Try

最佳答案

我想你不会找到那么多只有 TLS1.3 的网站
我使用这个功能很多年了:

  Function getFromURL(ByVal url As String) As String
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
'request.Headers.Add("HTTP_USER_AGENT", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.40607; .NET CLR 1.1.4322; .NET CLR 2.0.50215)")
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
Dim response As System.Net.WebResponse

response = request.GetResponse()

Dim responseStream As System.IO.Stream = response.GetResponseStream()

Dim reader As System.IO.StreamReader = New System.IO.StreamReader(responseStream)

Return reader.ReadToEnd()

End Function

关于VB.Net Web Scraper - 请求被中止 : Could not create SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67991928/

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