0
votes

Possibly a duplicate question. I have a SPA and implementing reCaptcha which I am running in localhost and gives me an error: "false\nincorrect-captcha-sol". The code I am using is shown below as from the original source here. It was working before with the same keys(private and public). What could I possibly change or check to make it work?Thanks

            var httpClient = new HttpClient();
        var PK = ConfigurationManager.AppSettings["recaptchaKey"];//private key
        var userIP = ((HttpContextBase)this.Request.Properties["MS_HttpContext"]).Request.UserHostAddress;
        var uri = "http://www.google.com/recaptcha/api/verify";

        var postData = new List<KeyValuePair<string, string>>();
        postData.Add(new KeyValuePair<string, string>("privatekey", PK));
        postData.Add(new KeyValuePair<string, string>("remoteip", userIP));
        postData.Add(new KeyValuePair<string, string>("challenge", data.Challenge));
        postData.Add(new KeyValuePair<string, string>("response", data.Response));

        HttpContent content = new FormUrlEncodedContent(postData);

        string responseFromServer = await httpClient.PostAsync(uri, content)
                .ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode())
                .ContinueWith((readTask) => readTask.Result.Content.ReadAsStringAsync().Result);

        if (responseFromServer.StartsWith("true"))
        {
            return Contact(data);
        }
1

1 Answers

0
votes

Following the docs your are posting to the wrong URL Its siteverify instead of Just verify in the end. https://developers.google.com/recaptcha/docs/verify