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

标签 vb.net ssl web web-scraping

我正在开发一个网络抓取程序,在禁用 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/

相关文章:

vb.net - 在脚本中启动应用程序并按住 Ctrl 键执行应用程序

具有自定义基本身份验证的 WCF 安全性

perl - 将 LWP 与 SSL 和客户端证书结合使用

java - .docx 正在从 Sun One Web 服务器下载为 IE 上的 .zip 文件

java - 如何处理1 :N Foreign Key for CRUD in Spring MVC/Hibernate?

java - 从服务器下载html文件

vb.net - 将工作分为多个线程

vb.net - AxShockwaveFlash.CallFunction() 帮助 (VB 2008)

string - 如何限制我可以保存的值?

c++ - OpenSSL SSL_read 失败(错误 :00000005:lib(0):func(0):DH lib)