2016-05-30 129 views
0

我想驗證使用requestify的recaptcha。這就是文檔說,有關API:使用requestify驗證google recaptcha?

API Request 

URL: https://www.google.com/recaptcha/api/siteverify 

METHOD: POST 

POST  Parameter Description 
secret Required. The shared key between your site and ReCAPTCHA. 
response Required. The user response token provided by the reCAPTCHA to the user and provided to your site on. 
remoteip Optional. The user's IP address. 

這是我的要求

我得到的迴應是

{ 
    "success": false, 
    "error-codes": [ 
    "missing-input-response", 
    "missing-input-secret" 
    ] 
} 

我想我可能被張貼在參數錯誤的方式或者我誤解了api文檔。

+0

我希望你的祕密不是真正的私鑰。哪些應該保持「私人」 – Martial

+0

這只是一個開發祕密,但謝謝! – Himmators

回答

0

我使用「請求」,但它應該以同樣的方式工作。

var request = require('request'); 

var data = { 
    remoteip: req.connection.remoteAddress, // @IP of the user 
    response: req.body["g-recaptcha-response"], 
    secret: RECAPTCHA_PRIVATE_KEY 
}; 

request.post({ 
    'url': RECAPTCHA_URL, 
    form: data, 
    'proxy': HTTP_PROXY // (optional) I'm behind a proxy 
}, function (error, response, body) { 
    if (!error && response.statusCode == 200) { 
    var b = JSON.parse(body); 
    if (b.success === true) { 
     // ... your code here 
    } else // ... 
    } else // .... 

});