4

I am trying to post to recapture from c# code.

        var data = new NameValueCollection
        {
            { "privatekey", "my key" },
            { "remoteip ", "" },
            { "challenge ", model.recaptcha_challenge_field },
            { "response ", model.recaptcha_response_field }
        };

        using (var client = new WebClient())
        {

            var response = client.UploadValues("http://www.google.com/recaptcha/api/verify", data: data);

            var result = ASCIIEncoding.ASCII.GetString(response);

        }

When I do this result is returning

false invalid-request-cookie

Do I need to set the remote IP? What else could be going wrong?

Update

https://developers.google.com/recaptcha/docs/verify says the error means:

https://developers.google.com/recaptcha/docs/verify

The value of the html on page is as follows:

<INPUT id=recaptcha_challenge_field value=03AHJ_VusdI2SY_P2iM3VICgLmOw-7CE7F6zmOwvwfya4L8Jeiok_rCwVmHFJwJHxlelhp8By_QTA7SNF58fwijij5rxBLqgpoI3nuWy6S0HGL7U7lk_35aazPfaMyVwbeWuWJyxJ0DqjwDwrByD4AY70O0qlaTnCUxQ type=hidden name=recaptcha_challenge_field />

In the object I post back it is as follows:

“recaptcha_challenge_field=03AHJ_VusdI2SY_P2iM3VICgLmOw-7CE7F6zmOwvwfya4L8Jeiok_rCwVmHFJwJHxlelhp8By_QTA7SNF58fwijij5rxBLqgpoI3nuWy6S0HGL7U7lk_35aazPfaMyVwbeWuWJyxJ0DqjwDwrByD4AY70O0qlaTnCUxQ&recaptcha_response_field=remerh+much"

and when i get it on the server the value is

03AHJ_VusdI2SY_P2iM3VICgLmOw-7CE7F6zmOwvwfya4L8Jeiok_rCwVmHFJwJHxlelhp8By_QTA7SNF58fwijij5rxBLqgpoI3nuWy6S0HGL7U7lk_35aazPfaMyVwbeWuWJyxJ0DqjwDwrByD4AY70O0qlaTnCUxQ

So if we put all 3 value side by side we have:

03AHJ_VusdI2SY_P2iM3VICgLmOw-7CE7F6zmOwvwfya4L8Jeiok_rCwVmHFJwJHxlelhp8By_QTA7SNF58fwijij5rxBLqgpoI3nuWy6S0HGL7U7lk_35aazPfaMyVwbeWuWJyxJ0DqjwDwrByD4AY70O0qlaTnCUxQ 
03AHJ_VusdI2SY_P2iM3VICgLmOw-7CE7F6zmOwvwfya4L8Jeiok_rCwVmHFJwJHxlelhp8By_QTA7SNF58fwijij5rxBLqgpoI3nuWy6S0HGL7U7lk_35aazPfaMyVwbeWuWJyxJ0DqjwDwrByD4AY70O0qlaTnCUxQ 
03AHJ_VusdI2SY_P2iM3VICgLmOw-7CE7F6zmOwvwfya4L8Jeiok_rCwVmHFJwJHxlelhp8By_QTA7SNF58fwijij5rxBLqgpoI3nuWy6S0HGL7U7lk_35aazPfaMyVwbeWuWJyxJ0DqjwDwrByD4AY70O0qlaTnCUxQ

The recapture on the page is being generated by calling the following:

Recaptcha.create("pub key",
    "myDiv",
    {
        theme: "clean",
        callback: Recaptcha.focus_response_field
    }
  );
1
  • 2
    I bet the request cookie is invalid! May 3, 2012 at 2:09

2 Answers 2

4

You have left spaces in remoteip,challenge and response parameters. It should be

var data = new NameValueCollection
        {
            { "privatekey", "my key" },
            { "remoteip", "192.168.1.111" },
            { "challenge", model.recaptcha_challenge_field },
            { "response", model.recaptcha_response_field }
        };

Also IP address is required but the current error you are getting is because of the leading spaces in your parameters.

0

The reCAPTCHA specification clearly states that the "remoteip" parameter is indeed required:

https://developers.google.com/recaptcha/docs/verify

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.