如果我在浏览器中运行该 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;
}
}
}