Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# reCaptcha不适用于我的私钥和公钥(但适用于google测试密钥)_C#_Asp.net_Recaptcha - Fatal编程技术网

C# reCaptcha不适用于我的私钥和公钥(但适用于google测试密钥)

C# reCaptcha不适用于我的私钥和公钥(但适用于google测试密钥),c#,asp.net,recaptcha,C#,Asp.net,Recaptcha,我已经排除了几个小时了。当我使用Google的公共和私有测试密钥时,我的代码可以工作。有什么我遗漏的吗 我可以采取哪些其他步骤来测试此代码 public static bool Validate(string encodedResponse) { if (string.IsNullOrEmpty(encodedResponse)) return false; var client = new System.Net.WebClient(); var secret = We

我已经排除了几个小时了。当我使用Google的公共和私有测试密钥时,我的代码可以工作。有什么我遗漏的吗

我可以采取哪些其他步骤来测试此代码

public static bool Validate(string encodedResponse)
{
    if (string.IsNullOrEmpty(encodedResponse)) return false;

    var client = new System.Net.WebClient();
    var secret = WebConfigurationManager.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 serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

    var reCaptcha = serializer.Deserialize<ReCaptcha>(googleReply);

    return reCaptcha.Success;
}
公共静态bool验证(字符串编码响应)
{
if(string.IsNullOrEmpty(encodedResponse))返回false;
var client=new System.Net.WebClient();
var secret=WebConfigurationManager.AppSettings[“Google.ReCaptcha.secret”];
if(string.IsNullOrEmpty(secret))返回false;
var googleReply=client.DownloadString(string.Format(“https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1},secret,encodedResponse);
var serializer=new System.Web.Script.Serialization.JavaScriptSerializer();
var reCaptcha=serializer.Deserialize(googleReply);
回归成功;
}

paul在这个链接上的代码:

您缺少Google的响应,这使得您很难找出问题var-reCaptcha的属性值,特别是JSON本机错误代码应该告诉您发生了什么。有一件事可能是,您正在测试此功能的主机名未注册为与您的ReCaptcha帐户一起使用(我一直是该帐户的受害者)