ReCaptcha 2.0远程服务器返回了ERror(错误请求)

时间:2018-07-17 12:58:14

标签: .net recaptcha

我的应用中有以下Recaptcha调用

var result = false;

        var apiUrl = "https://www.google.com/recaptcha/api/siteverify";

        var request = (HttpWebRequest)WebRequest.Create(apiUrl);
        request.Method = "POST";


        string postString = string.Format("secret={0}&response={1}&remoteIp=127.0.0.1", ReCaptcha_Secret, res);
        const string contentType = "application/x-www-form-urlencoded";
        byte[] byteArray = Encoding.UTF8.GetBytes(postString);
        request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
        request.ContentType = contentType;
        request.ContentLength = postString.Length;
        StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
        requestWriter.Write(postString);
        requestWriter.Close();


        try
        {
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader stream = new StreamReader(response.GetResponseStream()))
                {
                    JObject jResponse = JObject.Parse(stream.ReadToEnd());
                    var isSuccess = jResponse.Value<bool>("success");
                    result = (isSuccess) ? true : false;
                }
            }
            return result;
        }
        catch (Exception e)
        {
            return false;
        }

这个秘密和答案是正确的,但是无论我做什么,我总是收到消息:

  

{“远程服务器返回错误:(400)错误的请求。”}

来自我的开发环境,我已经在验证码中注册了127.0.0.1

我在这里想念什么吗?我花了整整一天的时间来尝试这项工作,我为此分配了2个小时的工作。

有什么建议吗?

修改

res是验证码挑战生成给用户的响应代码 根据文档,我需要这个和secret_key以获得我的回复

0 个答案:

没有答案