Recaptcha PostAsync抛出system.net.webeexception:底层连接已关闭



尝试实现谷歌验证码,在本地它工作得很好。但是当部署到其他服务器(通过Octopus)时,它会抛出异常。无法找到原因。发生在PostAsync调用,请帮助。

using (HttpClient client = new HttpClient())
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls12;
client.Timeout = TimeSpan.FromMilliseconds(this.ValidationTimeoutMiliseconds);                    

var values = new Dictionary<string, string>
{
{ "secret", Secret },
{ "response", value as string }
};

LogHelper.WriteLog("Start: Recaptcha requestdata is about to post to google...");
var response = client.PostAsync("https://www.google.com/recaptcha/api/siteverify", new FormUrlEncodedContent(values)).GetAwaiter().GetResult();
LogHelper.WriteLog("End: Recaptcha requestdata is posted successfully");

var responseString = response.Content.ReadAsStringAsync().Result;
var responseModel = JsonConvert.DeserializeObject<GRecaptchaValidationResponseModel>(responseString);

if (responseModel.ErrorCodes != null && responseModel.ErrorCodes.Contains("invalid-input-secret"))
LogHelper.WriteLogAsync("Invalid input secret for reCaptcha. Please configure in advanced settings parameters for Forms.");

return responseModel.Success;
}

抛出异常:在发送到google recaptcha时发生了一个异常:system.net.webeexception:底层连接已关闭:发送时发生了意外错误。——比;System.IO.IOException: cannot to read data from the transport connection:一个已存在的连接被远程主机强制关闭。——比;System.Net.Sockets.SocketException:已存在的连接被远程主机强制关闭在System.Net.Sockets.Socket。EndReceive (IAsyncResult asyncResult)在System.Net.Sockets.NetworkStream。EndRead (IAsyncResult asyncResult)——内部异常堆栈跟踪结束——在System.Net.TlsStream。EndWrite (IAsyncResult asyncResult)在System.Net.ConnectStream。WriteHeadersCallback (IAsyncResult ar)——内部异常堆栈跟踪结束——在System.Net.HttpWebRequest。EndGetRequestStream(IAsyncResult asyncResult, TransportContext&上下文)在System.Net.Http.HttpClientHandler。GetRequestStreamCallback (IAsyncResult ar)

谢谢解决,服务器有防火墙问题阻塞。解析后,工作正常。

相关内容

  • 没有找到相关文章

最新更新