How to post "secret" and "response" in Node.js?

1,619 views
Skip to first unread message

Jack Wang

unread,
Mar 6, 2016, 7:53:52 AM3/6/16
to reCAPTCHA
Hi,

I m using V2.0 of reCAPTCHA. Following is my back end code in Node.js to POST  "secret" and "response" to google service.

    var request = require('request');
    request.post({
        data: {
            secret: reCaptchaKey,
            response: req.body['g-recaptcha-response']      
        }
    }, function(error, response, body){
        console.log('body: '+body.success);
    });

But I received error code: "missing-input-secret" and "missing-input-response".

I also tried
    request.post({
        json: true,
        body: {
             secret: reCaptchaKey,
            response: req.body['g-recaptcha-response']             
        }
    }, function(error, response, body){
       // console.log(response);
        console.log('body: '+body.success+', '+body[error-codes].toString());
    });

and got the same error code.

I then tried V1.0 of reCAPTCHA which uses GET method, and it works!

So, could anyone please help how I should send  "secret" and "response" in my Node.js code for V2.0 of reCAPTCHA?

Thanks in advance
Jack

Seth Munroe

unread,
Mar 6, 2016, 4:28:40 PM3/6/16
to reCAPTCHA
This article:

makes it look like you should be using the form post:
request({
  uri: "https://www.google.com/recaptcha/api/siteverify",
  method: "POST",
  form: {

    secret: reCaptchaKey,
    response: req.body['g-recaptcha-response']
} }, function(error, response, body) {

  console.log(body);
});

Also make sure that the value of reCaptchaKey is the private key and not the public key.

-Seth

Jack Wang

unread,
Mar 7, 2016, 5:16:22 AM3/7/16
to reCAPTCHA
Thank you so much, Seth. It works now!
Reply all
Reply to author
Forward
0 new messages