Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:44:59+00:00 2026-06-14T14:44:59+00:00

I am using ReCaptcha with the javascript API on my aspx page on localhost.

  • 0

I am using ReCaptcha with the javascript API on my aspx page on localhost. I read somewhere that I don’t need a key as long as I use it on localhost. So, I use some random key that I found somewhere. I could render the recaptcha challenge successfully. The following is my javascript code.

Recaptcha.create("6Ld4iQsAAAAAAM3nfX_K0vXaUudl2Gk0lpTF3REf", 'captchadiv',
{
    tabindex: 1,
    theme: "clean",
    callback: Recaptcha.focus_response_field
});


//To Validate user response
function Recaptcha_IsCorrect()
{
    var xmlHttpRequest;
    var PageURL = document.URL;
    var xmlDoc;

    if (window.XMLHttpRequest)
    {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else
    {
        xmlHttpRequest = new ActiveXObject("Microsoft.xmlHttpRequest");
    }

    var challenge = Recaptcha.get_challenge();
    var userResponse = Recaptcha.get_response();

    var url = "../Ajax/PIAsyncAjax.asmx/ValidateReCaptcha?clientIP=127.0.0.1&privateKey=6Ld4iQsAAAAAAM3nfX_K0vXaUudl2Gk0lpTF3REf&challenge=" + challenge + "&response=" + userResponse;

    xmlHttpRequest.open("GET", url);
    xmlHttpRequest.onreadystatechange = function ()
    {
        if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200)
        {
            alert(xmlHttpRequest.responseText);
        }
    };

    xmlHttpRequest.send();
}    

The following is my code for the webservice which exposed the webmethod to validate ReCaptcha user input. I get the error “invalid-site-private-key”.

namespace YADA.YADAYADA{

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]   
public class PIAsyncAjax : System.Web.Services.WebService
{       
    [WebMethod]
    public string ValidateReCaptcha(string clientIP, string privateKey, string challenge, string response)
    {

        bool isValid = false;
        string validationResponse = "";

        reCaptchaValidation validator =
            new reCaptchaValidation(null,       
                                    clientIP,
                                    privateKey,
                                    challenge,
                                    response);

        isValid = validator.Validate();

        if (isValid)
        {
            validationResponse = "true";
        }
        else
        {
            if (!validator.IsErrored)
            {
                validationResponse = "false";
            }
            else
            {
                // oh dear, something not right

                if (validator.Exception != null)        // an exception occurred while 
                    // trying to validate
                    validationResponse = validator.Exception.ToString();
                else if (validator.ValidationResult != null)  // the validation web service 
                    // returned an error code 
                    // (other than an invalid captcha solution)
                    validationResponse = "web service error: " + validator.ValidationResult;
            }
        }

        return validationResponse;
    }
}


public class reCaptchaValidation
{
    private string challenge, response, privateKey, ip;
    private IWebProxy proxy;

    public reCaptchaValidation(string clientIP, string privateKey, 
    string challenge, string response) : this(null, clientIP, privateKey, 
    challenge, response) { }

    public reCaptchaValidation(IWebProxy proxy, string clientIP, 
        string privateKey, string challenge, string response)
    {
        this.proxy = proxy;
        this.ip = clientIP;
        this.privateKey = privateKey;
        this.challenge = challenge;
        this.response = response;
    }

    private bool _errored;
    public bool IsErrored
    {
        get
        {
            return _errored;
        }
    }

    private Exception _ex;
    public Exception Exception
    {
        get
        {
            return _ex;
        }
    }

    private string _vr;
    public string ValidationResult
    {
        get
        {
            return _vr;
        }
    }

    public bool Validate()
    {
        try
        {
            string post = "privatekey=" + HttpUtility.UrlEncode(privateKey) + 
        "&remoteip=" + HttpUtility.UrlEncode(ip) + "&challenge=" + 
        HttpUtility.UrlEncode(challenge) + "&response=" + 
        HttpUtility.UrlEncode(response);

            WebRequest wr = HttpWebRequest.Create
            ("http://www.google.com/recaptcha/api/verify");
            wr.Method = "POST";

            if (proxy != null)
                wr.Proxy = proxy;

            wr.ContentLength = post.Length;
            wr.ContentType = "application/x-www-form-urlencoded";
            using (StreamWriter sw = new StreamWriter(wr.GetRequestStream()))
            {
                sw.Write(post);
                sw.Close();
            }

            HttpWebResponse resp = (HttpWebResponse)wr.GetResponse();
            using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
            {
                string valid = sr.ReadLine();
                if (valid != null)
                {
                    if (valid.ToLower().Trim() == "false")
                    {
                        string errorcode = sr.ReadLine();

                        if (errorcode != null)
                        {
                            if (errorcode.ToLower().Trim() != "incorrect-captcha-sol")
                            {
                                _vr = errorcode;
                                _errored = true;
                                return false;
                            }
                        }
                    }

                    return (valid.ToLower().Trim() == "true");
                }
                else _vr = "empty web service response";

                sr.Close();
                return false;
            }
        }
        catch (Exception caught)
        {
            _errored = true;
            _ex = caught;
        }
        return false;
    }
}}

What am I doing wrong? Should I have to get a private key? Any help would be great.

Thanks in advance,
Venkat.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:45:00+00:00Added an answer on June 14, 2026 at 2:45 pm

    It works with the public and private keys that I just created. Damn, I just assumed, “localhost” would not be accepted as a legal domain-name while signing up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading reCAPTCHA via JavaScript http://www.google.com/recaptcha/api/js/recaptcha_ajax.js and am using jquery-1.5.2.min.js to communicate with a
I need to load the Recaptcha library on demand, with javascript (using Prototype): var
I've read this article, Using reCAPTCHA with Google App Engine , it wasn't very
I'm using Rails 3.1, and trying to setup Recaptcha so that it only shows
My page is http://bonemarrow.ipage.com/contact/ . I'm using reCaptcha with Contact Form 7 under a
I'm using recaptcha on my java jsp setup. I use the following code in
I'm using a reCaptcha class (the one that's included in the Tank Auth authentication
I using a reCaptcha on my web page under asp.net mvc. This web site
Hi all I am using reCaptcha in my page its a contact page. I
Recaptcha: i want to use recaptcha for the login page of my site which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.