ReCAPTCHA 关闭底层连接

Rex*_*lly 4 vb.net recaptcha

在 VS2012 (VB.Net) 中运行我的 ReCAPTCHA 例程,出现错误

基础连接已关闭。接收时发生意外错误

这段代码已经工作了几个星期,现在这周决定给我上面的错误。

有人可以告诉我问题是什么吗?谢谢!

这是我的代码:

        Dim recaptchaResponse As String = Request.Form("g-recaptcha-response")
        If Not String.IsNullOrEmpty(recaptchaResponse) Then
            Dim request As Net.WebRequest = Net.WebRequest.Create("https://www.google.com/recaptcha/api/siteverify?secret={MySecretKey}&response=" + recaptchaResponse)
            request.Method = "POST"
            request.ContentType = "application/json; charset=utf-8"
            Dim postData As String = ""

            'get a reference to the request-stream, and write the postData to it
            Using s As IO.Stream = request.GetRequestStream()
                Using sw As New IO.StreamWriter(s)
                    sw.Write(postData)
                End Using
            End Using

            '**This next line of code triggers the error**
            Using s As IO.Stream = request.GetResponse().GetResponseStream()
                Using sr As New IO.StreamReader(s)
                    'decode jsonData with javascript serializer
                    Dim jsonData = sr.ReadToEnd()
                    If jsonData.IndexOf("{" & vbLf & "  ""success"": true,") > -1 Then
                        Return True
                    Else
                        lblError.Text = jsonData
                    End If
                End Using
            End Using
Run Code Online (Sandbox Code Playgroud)

Rex*_*lly 6

内部异常是:

System.ComponentModel.Win32Exception (0x80004005): The client and server cannot communicate, because they do not possess a common algorithm at System.New.SSPIWrapper.AcquireCredentialsHandle
Run Code Online (Sandbox Code Playgroud)

我发现网络管理员决定在没有告诉我的情况下实施对 TLS 1.0 协议的禁令。

此问题的解决方法是确保 ReCAPTCHA 通过 TLS 1.2 进行通信。这是通过例程顶部的额外代码行完成的:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Run Code Online (Sandbox Code Playgroud)