【发布时间】:2021-04-17 13:29:25
【问题描述】:
如果我在浏览器中运行该 URL,则该 URL 有效,因此密钥和响应是正确的。但是,当我在本地运行代码时,它会引发 503 错误。有什么想法吗?
using System.Collections.Generic;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
namespace ProjectM2.Shared
{
public class ReCaptcha
{
public bool Success { get; set; }
public List<string> ErrorCodes { get; set; }
public static bool Validate(string encodedResponse)
{
if (string.IsNullOrEmpty(encodedResponse)) return false;
var client = new System.Net.WebClient();
var secret = ConfigurationManager.AppSettings["Google.ReCaptcha.Secret"];
if (string.IsNullOrEmpty(secret)) return false;
var googleReply = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, encodedResponse));
var reCaptcha = JsonConvert.DeserializeObject<ReCaptcha>(googleReply);
return reCaptcha.Success;
}
}
}
【问题讨论】:
-
在代码开头添加以下内容:ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
-
感谢您的及时回复,不幸的是,这并没有解决我的问题。
-
我要感谢大家的回复。我已经审查了您的所有建议,但没有成功。我仍然收到“远程服务器返回错误:(503)服务不可用。”错误。