在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
答案 0 :(得分:2)
内部例外是:
System.ComponentModel.Win32Exception (0x80004005): The client and server cannot communicate, because they do not possess a common algorithm at System.New.SSPIWrapper.AcquireCredentialsHandle
我发现网络管理员决定在不告诉我的情况下实施TLS 1.0协议禁令。
此问题的解决方法是确保ReCAPTCHA通过TLS 1.2进行通信。这是通过例程顶部的额外代码行完成的:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12