c# Authentication failed Google ReCaptcha
Posted
技术标签:
【中文标题】c# Authentication failed Google ReCaptcha【英文标题】: 【发布时间】:2019-05-11 18:56:13 【问题描述】:我正在尝试在我的项目中包含 Google ReCaptcha 验证,因此在我的 C# 类 a 中有以下代码执行验证密钥的请求:
try
string Response = Request["g-recaptcha-response"];
bool Valid = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = delegate
return true;
;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create
("https://www.google.com/recaptcha/api/siteverify?secret=MYKEY&response=" + Response);
using (WebResponse wResponse = req.GetResponse())
using (StreamReader readStream = new StreamReader(wResponse.GetResponseStream()))
string jsonResponse = readStream.ReadToEnd();
...
catch (WebException ex)
...
但我不断收到以下异常。由于我包括了 SecurityProtocol 开关,我没想到会收到这种错误。我在这里错过了什么吗?我的项目基于 .NET 框架 4.5。我已经遇到过这种错误,但它通过包含 SecurityProtocol 开关得到解决,但这次没有。
底层连接已关闭:发送时发生意外错误。 System.IO.IOException:身份验证失败,因为远程方已关闭传输流。在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState。 CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Threading.ExecutionContext .RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback , 对象状态) 在 System.Net.TlsStream.ProcessAuthentication(LazyAs syncResult 结果)在 System.Net.TlsStream.Write(Byte[] 缓冲区,Int32 偏移量,Int32 大小)在 System.Net.ConnectStream.WriteHeaders(布尔异步)
【问题讨论】:
Validating Recaptcha 2 (No CAPTCHA reCAPTCHA) in ASP.NET's server side的可能重复 【参考方案1】:刚刚通过删除这些行解决了问题。
ServicePointManager.ServerCertificateValidationCallback = delegate
return true;
;
【讨论】:
以上是关于c# Authentication failed Google ReCaptcha的主要内容,如果未能解决你的问题,请参考以下文章
YAPI内网部署问题:MongoNetworkError: Authentication failed., mongodb Authentication failed
如何解决“令牌检索失败:AUTHENTICATION_FAILED”?
sourcetree Authentication failed
mongoexport遭遇Authentication failed
on namespace ceilometer.$cmd failed: Authentication failed. 问题处理方案